Benjamin D Adams wrote:
I'm trying to check a string for ../
<?php
if(preg_match("/..//i", $string)){
echo "string has ../";
}
?>
Can't get it to work can anyone help?
That's terrible overkill. Regex is not designed for simple substring
matching. You want:
if( strpos( $string, '../' ) !== false )
echo 'string has ../';
By the way, your problem is that . is a special character in regular
expressions, so needs escaping with a backslash, and you have used / as
your delimiter but also use it inside the pattern. You should use a
different delimiter (also, there's no point in using the 'i'
case-insensitive flag, since there's no characters in your pattern).
The strpos() solution above is much better and faster in this case, though.
--
Jasper Bryant-Greene
General Manager
Album Limited
http://www.album.co.nz/ 0800 4 ALBUM
jasper@xxxxxxxxxxx 021 708 334
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php