I'm attempting to make use of this project on GitHub https://github.com/ErisDS/Migrate emigrate the URL configurations during my Wordpress database from the Localhost dev install to some live URL.

Right now the code throws a mistake for that Hyperlink to be changed "http://localhost/mysitename", but does accept the brand new URL "http://www.mywebsitename.com"

From what I will tell the mistake originates from this regular expression not validating the localhost like a valid URL - any ideas the way i can update this to simply accept the localhost URL?

The entire code could be seen on GitHub.

function checkURL($url)
 {
  $url_regex = '/^(http\:\/\/[a-zA-Z0-9_\-]+(?:\.[a-zA-Z0-9_\-]+)*\.[a-zA-Z]{2,4}(?:\/[a-zA-Z0-9_]+)*(?:\/[a-zA-Z0-9_]+\.[a-zA-Z]{2,4}(?:\?[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)?)?(?:\&[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)*)$/';
if($url == 'http://')
 {
 return false;
 }    
return preg_match($url_regex, $url);
}

It isn't working because somewhere within the regex you're requesting a us dot among http:// and /. http://localhost/whatever doesn't have us dot, therefore it fails.

You should be utilising something similar to [cde] or [cde] rather than regexes for URL validation.

The Writer from the MIGRATE scripts has up-to-date the project on GitHub to incorporate this fix. interesting help men.

https://github.com/ErisDS/Migrate

You can include "localhost" towards the acceptable hostnames by altering it for this:

/^(http\:\/\/(?:[a-zA-Z0-9_\-]+(?:\.[a-zA-Z0-9_\-]+)*\.[a-zA-Z]{2,4}|localhost)(?:\/[a-zA-Z0-9_]+)*(?:\/[a-zA-Z0-9_]+\.[a-zA-Z]{2,4}(?:\?[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)?)?(?:\&[a-zA-Z0-9_]+\=[a-zA-Z0-9_]+)*)$/

This part matches the http:// prefix:

http\:\/\/

Which part matches the hostname:

[a-zA-Z0-9_\-]+(?:\.[a-zA-Z0-9_\-]+)*\.[a-zA-Z]{2,4}

So that you can just alter the hostname checker to some non-taking alternation group that clearly includes "localhost":

(?:X|localhost)

where X may be the existing hostname matching sub-expression. The (?: bit begins a non-taking group, utilizing a non-taking group guarantees that any group number references will not get screwed up.

Plus some live good examples: http://ideone.com/M0qqh

I believe an easy regex might last better though, that certain does not cope with CGI parameters perfectly. You could attempt this:

/(http:\/\/[^\/]+\/([^\s]+[^,.?!:;])?)/

and find out whether it works best for your computer data. That certain is fairly loose but most likely adequate for any one-shot conversion. Which should correctly match the Web addresses during these:

'here is a URL http://localhost/x?a=b.'
'More http://example.com nonsense!.

You might try Joseph's in the comment.