View Full Version : strchr()

03-07-2007, 05:20 PM
Note: Realised my error and fixed, please ignore this post. I had misread strchr, it should be strrchr in the code below :rolleyes: .

From php.net (http://uk2.php.net/manual/en/function.strrchr.php):

string strrchr ( string $haystack, string $needle )

This function returns the portion of haystack which starts at the last occurrence of needle and goes until the end of haystack.

Given the above, shouldn't the following code echo "/foo.htm"?

$url = "http://www.domain.com/foo.htm";
$exc = strchr($url, "/");
echo $exc;

For me it's returning "//www.domain.com/foo.htm" which seems to be a portion that starts at the first occurence of needle and goes until the end of haystack (ie, the written purpose of strstr() (http://uk2.php.net/manual/en/function.strstr.php))
. :confused:

03-07-2007, 11:38 PM
emm you quoted function strrchr form php.net, but you using strchr witch is alias of strstr function :)