所以我在下面有这个代码,但我想知道如何判断'$ 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);
}
答案 0 :(得分: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";
}