Page 1 of 1

another regexp question

Posted: Fri May 21, 2004 11:19 am
by mortz
I've played some with regular expressions and found out that this line works:

Code: Select all

<?php
if (ereg("[h][t][t][p][:][/][/]", $page) || ereg("^[/]", $page) || ereg("[.][/]", $page) || ereg("[.][.][/]", $page)) echo "ERROR!";
?>
There must be an easier way, right?

Re: another regexp question

Posted: Fri May 21, 2004 11:34 am
by redmonkey
mortz wrote:I've played some with regular expressions and found out that this line works:

Code: Select all

<?php
if (ereg("[h][t][t][p][:][/][/]", $page) || ereg("^[/]", $page) || ereg("[.][/]", $page) || ereg("[.][.][/]", $page)) echo "ERROR!";
?>
There must be an easier way, right?
Your code is equivalent to...

Code: Select all

<?php
if (preg_match('/(http:\/\/|^\/|\.+?\/)/', $page))
{
  echo 'ERROR!';
}
?>

Posted: Fri May 21, 2004 12:54 pm
by mortz
Thanks!

All those strange characters gives me a headache :P
Guess I'll figure out how they work soon! :)