-3

if my $text is "color: green, size: 10cm, gift wrapped: yes" the string conses the words it failed to print "found"

 $text =$item_meta->display($flat=true,$return=true);
    $pos = strpos($text, 'gift wrapped: yes');
        if ($pos == false) {
            print "Not found\n";
        } else {
            print "Found!\n";
        }

this the piece of code i used to test but failed

can any one help me in this situation

papa.ramu
  • 423
  • 1
  • 5
  • 18
  • I have absolutely no idea what you're asking. What "failed"? How? And I'm pretty sure you're using default function arguments incorrectly. Perhaps you could work on your question-writing skill as all three pages of questions on your profile show the same pattern. – Lightness Races in Orbit Nov 25 '14 at 12:56
  • this could help you out.. http://stackoverflow.com/questions/4366730/check-if-string-contains-specific-words – Nishant Solanki Nov 25 '14 at 12:58
  • 1
    I ran your code with the text "color: green, size: 10cm, gift wrapped: yes" and it returned Found!. So make sure $text is actually what you think it is - print it out to debug :) – Kat Nov 25 '14 at 13:06

1 Answers1

0

This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Use the === operator for testing the return value of this function.

<?php
    $text ="color: green, size: 10cm, gift wrapped: yes";
    $pos = strpos($text, 'gift wrapped: yes');
    if ($pos === false) {
        print "Not found\n";
    } else {
        print "Found!\n";
    }

?>

rahul
  • 9
  • 1