【发布时间】:2018-08-10 10:30:59
【问题描述】:
这里是html:
<td width="551">
<p><strong>Full Time Faculty<br>
<strong></strong>Assistant Professor</strong></p>Doctorate of Business Administration<br><br>
<strong>Phone</strong>: +88 01756567676<br>
<strong>Email</strong>: frank.wade@email.com<br>
<strong>Office</strong>: NAC739<br>
<br><p><b>Curriculum Vitae</b></p></td>
我想要的输出是:
+88 01756567676
frank.wade@email.com
NAC739
我使用 simple_html_dom 来解析数据。
这是我编写的代码。如果联系信息部分用段落标签包裹,它就可以工作。 (
)
$contact = $facultyData->find('strong[plaintext^=Phone]');
$contact = $contact[0]->parent();
$element = explode("\n", strip_tags($contact->plaintext));
$regex = '/Phone:(.*)/';
if (preg_match($regex, $element[0], $match))
$phone = $match[1];
$regex = '/Email:(.*)/';
if (preg_match($regex, $element[1], $match))
$email = $match[1];
$regex = '/Office:(.*)/';
if (preg_match($regex, $element[2], $match))
$office = $match[1];
有什么方法可以通过标签匹配得到这3行吗?
【问题讨论】:
-
您可能想改用
DOMDocument。
标签: php dom web-crawler simple-html-dom