OpenCode Posted December 19, 2010 Share Posted December 19, 2010 Hello, I got a JavaScript URL Validation Regex, since I'm not used-to with Regex I need help converting it into PHP regex. Here is a JavaScript Regex /^https?\:\/\/(www\d?\d?\d?\d?\.)?([A-Za-z0-9-_]+\.)?[A-Za-z0-9-_]+((\.[A-Za-z]{2,6})(\.[A-Za-z]{2})?([0-9-_%&\?\/\.=]*))$/ I need this particular regex in PHP Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/222120-url-validation-javascript-regex-to-php-regex/ Share on other sites More sharing options...
OpenCode Posted December 21, 2010 Author Share Posted December 21, 2010 No solutions here ? If its there, here is the link what I need to be validated. $url="http://www.facebook.com/profile.php?id=66665555#!/home.php?sk=group_66665555&ap=1"; Quote Link to comment https://forums.phpfreaks.com/topic/222120-url-validation-javascript-regex-to-php-regex/#findComment-1149886 Share on other sites More sharing options...
.josh Posted December 21, 2010 Share Posted December 21, 2010 the regex is the same (the syntax is the same, though I can't vouch for the soundness of your pattern without knowing details...but if you know your current pattern works for you, then okay), but you would use the pattern in something like preg_match example: preg_match("/.../",$contentToMatch,$matches); echo "<pre>"; print_r($matches); first argument is the pattern, 2nd is the subject, 3rd are results of captured matches. Or if you are not caring about the captured groups and just wanting to know if the pattern matched overall: if (preg_match("/.../",$contentToMatch)) { // matched } else { // did not match } Quote Link to comment https://forums.phpfreaks.com/topic/222120-url-validation-javascript-regex-to-php-regex/#findComment-1150000 Share on other sites More sharing options...
ZachMEdwards Posted December 23, 2010 Share Posted December 23, 2010 Here's your Javascript pattern in PHP: '#^https?\:\/\/(www\d?\d?\d?\d?\.)?([A-Za-z0-9-_]+\.)?[A-Za-z0-9-_]+((\.[A-Za-z]{2,6})(\.[A-Za-z]{2})?([0-9-_%&\?\/\.=]*))$#' Quote Link to comment https://forums.phpfreaks.com/topic/222120-url-validation-javascript-regex-to-php-regex/#findComment-1150657 Share on other sites More sharing options...
.josh Posted December 23, 2010 Share Posted December 23, 2010 that's the same pattern except with different delimiters... yes, you can use more than / as a pattern delimiter in php but / works just fine, there is no need to change the pattern. Quote Link to comment https://forums.phpfreaks.com/topic/222120-url-validation-javascript-regex-to-php-regex/#findComment-1150794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.