Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 按特定字符串获取DIV内容_Php - Fatal编程技术网

Php 按特定字符串获取DIV内容

Php 按特定字符串获取DIV内容,php,Php,我喜欢中的解决方案,但我需要从包含特定字符串的DIV类中查找值,例如在我的示例中btx764839(例如)。div类的名称不仅仅是该字符串,例如76 我需要脚本来搜索包含btx764839的DIV,然后引用该特定DIV。我用strpos()尝试了许多不同的东西,但没有成功。下面是我在另一篇文章中找到的脚本(没有我的调整)。我希望能得到一些帮助。多谢各位 $url = 'url'; $content = file_get_contents($url); $first_step = explode(

我喜欢中的解决方案,但我需要从包含特定字符串的DIV类中查找值,例如在我的示例中btx764839(例如)。div类的名称不仅仅是该字符串,例如
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'