On 07/29/2009 02:07 PM, Jim Lucas wrote:
b wrote:
I'm trying to figure out how to test if a string matches *exactly*
another string, using a regexp pattern. The manual says that ereg() is
deprecated (in favour of what?) and preg_match() is giving me trouble.
The problem is that I'm passing the end-of-line delimiter ($) but it
seems to be ignored. An example:
-- snip --
header('Content-type: text/plain');
$url = '/foo(/)?';
$test = 'foo/bar';
$pattern = '%^'.$url.'$%U';
echo "${url} :: ${test}\n";
echo (preg_match($pattern, $test) != false)
? 'match'
: 'no match';
-- snip --
I expected 'no match' but get 'match'.
The reason for the (/)? is to allow for a trailing slash. I've added a
'$' to specify that I want to test for the exact string. However,
preg_match() tests for the existence of a string and appears to ignore
the '$'.
How do I do this?
cut/paste your code and it works for me.
Jim Lucas
Works, meaning you get 'match', or 'no match'? It should be the latter,
but I'm seeing the former.
I'm using 5.2.9, btw.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php