Php 按特定字符串获取DIV内容
我喜欢中的解决方案,但我需要从包含特定字符串的DIV类中查找值,例如在我的示例中btx764839(例如)。div类的名称不仅仅是该字符串,例如Php 按特定字符串获取DIV内容,php,Php,我喜欢中的解决方案,但我需要从包含特定字符串的DIV类中查找值,例如在我的示例中btx764839(例如)。div类的名称不仅仅是该字符串,例如76 我需要脚本来搜索包含btx764839的DIV,然后引用该特定DIV。我用strpos()尝试了许多不同的东西,但没有成功。下面是我在另一篇文章中找到的脚本(没有我的调整)。我希望能得到一些帮助。多谢各位 $url = 'url'; $content = file_get_contents($url); $first_step = explode(
76
我需要脚本来搜索包含btx764839的DIV,然后引用该特定DIV。我用strpos()尝试了许多不同的东西代码>,但没有成功。下面是我在另一篇文章中找到的脚本(没有我的调整)。我希望能得到一些帮助。多谢各位
$url = 'url';
$content = file_get_contents($url);
$first_step = explode( '<div class="dark btx764839">' , $content );
$second_step = explode("</div>" , $first_step[1] );
echo $second_step[0];
代码取自提供的示例:
foreach($divs as $div) {
// Loop through the DIVs looking for one withan id of "content"
// Then echo out its contents (pardon the pun)
// get class attribute of a div, it's a string
$class = $div->getAttribute('class');
// find substring 'btx764839' in $class
if (strpos($class, 'btx764839') !== false) {
echo $div->nodeValue;
}
}
代码取自提供的示例:
foreach($divs as $div) {
// Loop through the DIVs looking for one withan id of "content"
// Then echo out its contents (pardon the pun)
// get class attribute of a div, it's a string
$class = $div->getAttribute('class');
// find substring 'btx764839' in $class
if (strpos($class, 'btx764839') !== false) {
echo $div->nodeValue;
}
}
对不起,我不知道如何把你的代码和我的代码结合起来。代码引用了另一个页面的内容$url='url'代码>。对不起,我不知道如何将你的代码与我的代码结合起来。代码引用了另一个页面的内容$url='url'代码>。