-1

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
    }
    ...
2
  • 1
    Probably a line break / white space issue. Can you do a trim() on both values and see if they match then? Commented May 18, 2011 at 15:26
  • If you really want to check such strings, use var_dump Commented May 28 at 9:49

2 Answers 2

3

$test has a space after Availability: maybe you must trim strings before comporation. like that

if(trim($orig->title) == trim($prep[1]))
Sign up to request clarification or add additional context in comments.

Comments

0

I would say it's almost certain to be spaces on the begining and/or end of your strings.

For example, you are doing explode("Availability:",$test);, but your string has a space after 'Availability:', before 'Lorum', so $prep[1] will be equal to ' Lorum Ipsum' - with a leading space.

Either change your explode() call, or use trim() in your comparisons.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.