感谢您的回复。
我得到了我正在寻找的解决方案。
这是代码,以防有人需要。
Explanation :
'$results' is the curl response.
Enter div class name (which you want to fetch) inside "$xpath->query() function"
You will get source code for entire class inside "$tag->textContent"
$dom = new DOMDocument();
$dom->loadHTML($results);
$xpath = new DOMXPath($dom);
$tags = $xpath->query('//div[@class="e"]');
foreach ($tags as $tag)
{
echo "<br>----------<br>";
var_dump($tag->textContent);
echo "<br>----------<br>";
}
现在您在“$tag->textContent”中拥有了所需类的 html 源代码。
现在您可以使用以下函数从“开始”和“结束”点之间的字符串中获取任何内容。
function get_string_between($string, $start, $end){
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
就我而言,我是这样使用它的:
$price = get_string_between($tag->textContent,'swf', '+');
echo $price;
这里“swf”是路径的起点,“+”是终点。
希望它可以节省其他人的时间:)