Problem with $ in preg_match
Posted: Sun May 31, 2009 12:10 pm
I've got a form with a URL submission field. I take the submitted url, append a string to it, and get some information back from it.
My question comes when checking for the final forward slash in the root in the submission. I need to be able to append the string after the last forward slash because it won't work if I don't.
Here's what I have, but it's obviously not working.
This should return true, or at least thats what I am expecting. It seems to me that this code should work. I've checked it in numerous online REGEX editors and it does exactly what I want it to do. But when I try to implement into my code, I get an error message that reads:
Any ideas?
Thanks in advance.
My question comes when checking for the final forward slash in the root in the submission. I need to be able to append the string after the last forward slash because it won't work if I don't.
Here's what I have, but it's obviously not working.
Code: Select all
<?php
$url = "http://www.php.net/";
// Trying to check for a '/' at the end of the submitted url
$pattern = '//$/'; // I've also tried '/[/]$/' as the pattern
$check = preg_match( $pattern , $url );
if($check) {
echo "This url ends in a forward slash";
return true;
}
else {
echo "This url doesn't end in a forward slash";
return false;
}
?>I've been searching online for "end of string" indicators for php and regex, and even there it looks like this is the pattern I should be using.Warning: preg_match() [function.preg-match]: Unknown modifier '$'
Any ideas?
Thanks in advance.