Preg_match_all <a

后端 未结 6 1829
天命终不由人
天命终不由人 2020-12-02 02:25
6条回答
  •  难免孤独
    2020-12-02 03:13

    Don't use regular expressions for proccessing xml/html. This can be done very easily using the builtin dom parser:

    $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 . "
    \n"; }

提交回复
热议问题