substring compare

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
theclay7
Forum Commoner
Posts: 50
Joined: Wed Feb 19, 2003 3:17 am

substring compare

Post 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"
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

User avatar
Crashin
Forum Contributor
Posts: 223
Joined: Mon May 06, 2002 3:42 pm
Location: Colorado

Post 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.
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

the if condition must be wrapped in parenthesis. ;)



http://ca.php.net/manual/en/control-str ... uctures.if
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

the first ( is just at the wrong position, the amount is correct ;)
and yes, strpos() is probably more suitable.
Post Reply