
如何使用 querylist 从 html p 标签中提取数据
想要从 html 文档中提取 p 标签内的数据,可以使用专业的框架 querylist。
use QL\QueryList;
$html = '<p>第四章 医学微生物学(助理不考)</p><p>第一节 微生物的基本概念</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1840">
<img src="https://img.php.cn/upload/ai_manual/000/969/633/68b6c8ae5fa40470.png" alt="Change Style AI">
</a>
<div class="aritcle_card_info">
<a href="/ai/1840">Change Style AI</a>
<p>多风格照片生成器!AI生成30种照片</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="Change Style AI">
<span>167</span>
</div>
</div>
<a href="/ai/1840" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="Change Style AI">
</a>
</div>
<p><span>立即学习</span>“<a href="https://pan.quark.cn/s/cb6835dc7db1" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">前端免费学习笔记(深入)</a>”;</p>';
$ql = QueryList::html($html);
$data = $ql->find('p')->texts()->toArray();
// 결과 데이터
print_r($data);最终得到的 $data 数组包含了两个文本字符串,分别为 "第四章 医学微生物学(助理不考)" 和 "第一节 微生物的基本概念"。
以上就是如何用QueryList高效提取HTML p标签中的文本数据?的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号