0

So I have this code below but I am wondering how I can tell if '$text' contains the words 'by owner'. How do I do this? I looked around but I can't find anything.

foreach($anchors as $a) { 
    $i = $i + 1;
    $text = $a->nodeValue;
    $href = $a->getAttribute('href');
    if ($i > 22 && $i < 64 && ($i % 2) == 0) {
        //if ($i<80) {
         echo "<a href =' ".$href." '>".$text."</a><br/>";
    }
   // }
        //$str = file_get_contents($href);
//$result = (substr_count(strip_tags($str),"ipod"));
//echo ($result);
}
1

1 Answer 1

1

Something like:

$text = $a->nodeValue;
if(strpos($text, "by owner") == -1){  // if you want the text to *start* with "by owner", you can replace this with strpos($text, "by owner") != 0
    echo "Doesn't have by owner";
}
else{
    echo "Has by owner";
}
2
  • Thanks but is there a way that I could check for multiple sub strings? Commented Apr 20, 2013 at 1:16
  • As far as I know, PHP doesn't have that function. But you can build one yourself. See stackoverflow.com/a/9220624/898423 for an example. Commented Apr 20, 2013 at 1:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.