使用 querylist 快速读取 html 中 p 标签数据
在 html 页面中,想要读取 <p> 标签内的文本内容并将其分数组,可以使用基于 php 的开源框架 querylist。
步骤:
示例代码:
<?php require 'vendor/autoload.php'; use QLQueryList; $html = '<p>第四章 医学微生物学(助理不考)</p><p>第一节 微生物的基本概念</p>'; $ql = QueryList::html($html); $result = $ql->find('p')->texts()->toArray(); print_r($result); // 输出:Array ( [0] => 第四章 医学微生物学(助理不考) [1] => 第一节 微生物的基本概念 ) ?>
注: