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);
}
Eduard Luca
  • 6,514
  • 16
  • 85
  • 137
user1973004
  • 15
  • 1
  • 8
  • Are you just trying to check if `$text` has the substring `"by owner"`? Cause http://www.php.net/manual/en/function.strstr.php will do that... If you need case insensitivity, use http://www.php.net/manual/en/function.stristr.php . And http://www.php.net/manual/en/function.preg-match.php will allow you to use regular expressions to match variable spacing, exact words, etc. – FrankieTheKneeMan Apr 20 '13 at 00:12

1 Answers1

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";
}
Eduard Luca
  • 6,514
  • 16
  • 85
  • 137