1

I am kind of banging my head to the wall here. I am trying all sorts of URLs, and regex's some I made up, some I just found on the web.

It seems like PHP and Javascript don't interpret the strings the same. I need a string for a (GET params possibly) PHP and JAVASCRIPT that would work the same on the client and server side. As it is now, the client is ok, while the server isn't or the other way around.

Can anyone send such a string with it's equivalence php/javascript ?

Thanks so much in advance !

By the way, I use http://regexpal.com/ I think it is a great tool !

5
  • 2
    What exactly are you trying to do? Can you show an example? Commented Aug 20, 2011 at 18:15
  • Trying to validate a url field on the client side, and upon for submission, to validate it on my php server Commented Aug 20, 2011 at 18:20
  • I think I got something... I can't really post another answer, but I will write it here, sorry... $regex = '/^((https?|ftp)?\:\/\/)?([a-z0-9+!*(),;?&=\$_.-]+(\:[a-z0-9+!*(),;?&=\$_.-]+)?@)?([a-z0-9-.]*)\.([a-z]{2,3})(\:[0-9]{2,5})?(\/([a-z0-9+\$_-]\.?)+)*\/?(\?[a-z+&\$_.-][a-z0-9;:@&%=+\/\$_.-]*)?(#[a-z_.-][a-z0-9+\$_.-]*)?/'; if (preg_match($regex,$url)) { //$err_validation[]= 'url ok'; return true; } Commented Aug 20, 2011 at 18:21
  • Do a search for "validate URL" - this question gets asked a lot. Commented Aug 20, 2011 at 18:42
  • No. My example simply accepts wrong urls too.... Commented Aug 20, 2011 at 18:50

1 Answer 1

0

This should be useful to you: https://gist.github.com/729294

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it's very weird but when I set my $regex='that php long string', I get a weird error saying: Notice: Undefined variable: iuS in C:\xampp\htdocs\test.php on line 657 ......... What's weird about it is that it doesn't complain on the preg_match, but on the variable which I haven't even defined (it is $regex, not a part of the string), am I missing a point here ?
You used the long string in the comments? Try using '/^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$/iu'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.