Comparing Strings

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
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Comparing Strings

Post by spacebiscuit »

I'm comparing two strings, although they appear to be the same when I do a var)_dump they are not:

Code: Select all

string(71) "blah blah" string(96) "blah blah
Note that the closing quotation is missing from the second string. I've tried trim but this doesn't seem to work.

Any ideas?

Thanks.
phpHappy
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2011 1:58 pm

Re: Comparing Strings

Post by phpHappy »

not real sure what you want - if you want to know they are different in code -several ways to
if($str[71] == $str[96]) { your code if they are the same }
else { echo '"$str[71]" does not equal "$str[96]"';}
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: Comparing Strings

Post by spacebiscuit »

Ok I figured out the problem - I was using regex to populate the variables that were passed via the form. The regex had an error and unwanted characters were being matched, I fixed the regex and now it works.

Thanks for your help!
Post Reply