Re: preg_match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux