有没有办法将 html <b> 标签内的单词与 PHP 中的句子匹配
Is there a way to match words to sentences inside a html <b> tag in PHP
所以我有这段代码可以提取 b 标签之间的文本。
$source_url = "https://www.wordpress.com/";
$html = file_get_contents($source_url);
$dom = new DOMDocument;
@$dom->loadHTML($html);
$links = $dom->getElementsByTagName('b');
$words = "php";
echo "<pre>";
print_r($dom);
echo "</pre>";
我尝试使用 array_push 和其他方法将文本放入数组中,但如果我要使用 in_array
我需要把整个句子 return true 不仅仅是一个词。
所以我想要的是:
如果该句子包含 'php' 那么 return true
试试这个:
foreach($links as $link) {
$p = strtolower($link->nodeValue);
if (strpos($p, 'php') !== false) {
// do something
}
}
所以我有这段代码可以提取 b 标签之间的文本。
$source_url = "https://www.wordpress.com/";
$html = file_get_contents($source_url);
$dom = new DOMDocument;
@$dom->loadHTML($html);
$links = $dom->getElementsByTagName('b');
$words = "php";
echo "<pre>";
print_r($dom);
echo "</pre>";
我尝试使用 array_push 和其他方法将文本放入数组中,但如果我要使用 in_array 我需要把整个句子 return true 不仅仅是一个词。
所以我想要的是:
如果该句子包含 'php' 那么 return true
试试这个:
foreach($links as $link) {
$p = strtolower($link->nodeValue);
if (strpos($p, 'php') !== false) {
// do something
}
}