Avatar of n00b0101
n00b0101
 asked on

php - identical strings don't show up as a match

I'm trying to determine whether or not two strings match, and even though when I print them out, they're identical, it still says they don't match.  I tried to cast them both as strings, and I tried using '===' instead of '==', but neither solved the problem...

       if(preg_match("#^Availability:#", $test)) {
        //just to note: $test = "Availability: Lorem Ipsum";
        
        $nid = 1;
        $prep = explode("Availability:", $test);
        
        $orig = node_load($nid);
        
        print $prep[1];  //Prints Lorem Ipsum
        print($orig->title); //Prints Lorem Ipsum
        
        if((string)$orig->title	== (string)$prep[1]) { 
          print 'ok'; 
        } else { 
          print 'nope'; //Always prints nope
        }
        ...

Open in new window

PHPRegular Expressions

Avatar of undefined
Last Comment
kaufmed

8/22/2022 - Mon
lexlythius

instead of print, try
var_dump($prep[1]);
var_dump($orig->title);

Open in new window

and make sure there are no leading/trailing spaces in of of them.
zappafan2k2

You're not including the space after the colon in your explode() statement.  Therefore, $prep[1] = ' Lorem Ipsum', not 'Lorem Ipsum'.

You should try changing the explode statement to:
$prep = explode("Availability: ", $test);

Open in new window

ASKER CERTIFIED SOLUTION
zappafan2k2

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kaufmed

When you "exploded" the string, you did so on "Availability:", but you still left the space between ":" and "Lorem". I believe you are comparing " Lorem Ipsum" to "Lorem Ipsum". Spaces count in string comparison.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck