0

所以我在下面有这段代码,但我想知道如何判断'$text' 是否包含'by owner' 字样。我该怎么做呢?我环顾四周,但找不到任何东西。

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);
}
4

1 回答 1

1

就像是:

$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";
}
于 2013-04-20T01:06:59.010 回答