str*_*ade 2 php hyperlink preg-match
你好,我想提取链接
<a href="/portal/clients/show/entityId/2121" >
,我想要一个正则表达式给我/ portal/clients/show/entityId/2121最后2121的数字是在其他链接不同的任何想法?
kar*_*m79 10
// Create DOM from string
$html = str_get_html($links);
//or
$html = file_get_html('www.example.com');
foreach($html->find('a') as $link) {
echo $link->href . '<br />';
}
Run Code Online (Sandbox Code Playgroud)
不要使用正则表达式来处理 xml/html。这可以使用内置的 dom 解析器很容易地完成:
$doc = new DOMDocument();
$doc->loadHTML($htmlAsString);
$xpath = new DOMXPath($doc);
$nodeList = $xpath->query('//a/@href');
for ($i = 0; $i < $nodeList->length; $i++) {
# Xpath query for attributes gives a NodeList containing DOMAttr objects.
# http://php.net/manual/en/class.domattr.php
echo $nodeList->item($i)->value . "<br/>\n";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26604 次 |
| 最近记录: |