gpt4 book ai didi

php - 获取 Data-Prefilltext 属性中的内容

转载 作者:搜寻专家 更新时间:2023-10-31 20:40:13 26 4
gpt4 key购买 nike

我正在使用 PHP,并且我有这样的 HTML 代码

<button style="display:none" id="btnGGPShare0"  class="g-interactivepost" data-contenturl="http://www.tindich.com/18-bi-mat-vuot-thoi-gian-cua-nhung-nguoi-hanh-phuc/" data-clientid="208559429132-h4egkr4jjlagnk8r5jskic4d27oa4n4l.apps.googleusercontent.com" data-cookiepolicy="single_host_origin" data-prefilltext="Chúng ta thường nghe nói rằng sự nổi tiếng chỉ đem lại bất hạnh. Điều này không hề đúng! Vì cùng với một nhóm các nhà khoa học nghiên cứu về hạnh phúc, những người nổi tiếng của mọi thời đại đã cho biết họ có thể  chỉ ra được những bí mật để trở [&hellip;]" data-calltoactionurl="http://www.tindich.com/18-bi-mat-vuot-thoi-gian-cua-nhung-nguoi-hanh-phuc/" data-calltoactiondeeplinkid="/pages/create">

然后我想获取data-prefilltext属性双引号之间的所有内容。请为此建议我一些解决方案。非常感谢。

最佳答案

我会利用 DOM 来解析它并避免使用正则表达式。

$doc = new DOMDocument();
$doc->loadHTML($html); // Load your html data

$xpath = new DOMXPath($doc);
$node = $xpath->query("//button[@id='btnGGPShare0']");

echo $node->item(0)->getAttribute('data-prefilltext');

参见 Working Demo

如果您有多个要从中提取该属性的 button 标记,请改用循环。

$nodes = $xpath->query('//button');
foreach ($nodes as $node) {
echo $node->getAttribute('data-prefilltext') . "\n";
}

关于php - 获取 Data-Prefilltext 属性中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23905039/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com