Page 1 of 1

substring compare

Posted: Wed May 14, 2003 3:56 am
by theclay7
if I want to compare two strings...for example

$compare_1 = "http://www.codingforums.com/error.php?abc=123";

$compare_2 = "http://www.codingforums.com/index.php";

$compare = "error.php";


how do I get sub string from $compare_1 or $compare_2 to see if the URL has "error.php" (i.e. $compare)

if substr(($compare_1 has error.php) == $compare)
echo "matched";

how can I find if $compare_1 or $compare_2 consist of "error.php"

Posted: Wed May 14, 2003 4:00 am
by volka

Posted: Wed May 14, 2003 12:23 pm
by Crashin
You might look into:
Note: If you only want to determine if a particular needle occurs within haystack, use the faster and less memory intensive function strpos() instead.
From the same page referenced by volka.

Posted: Wed May 14, 2003 1:37 pm
by m3mn0n
the if condition must be wrapped in parenthesis. ;)



http://ca.php.net/manual/en/control-str ... uctures.if

Posted: Thu May 15, 2003 12:50 am
by volka
the first ( is just at the wrong position, the amount is correct ;)
and yes, strpos() is probably more suitable.