Finding links matching given string in xpath/domdocument query

前端 未结 2 1815
野性不改
野性不改 2020-12-18 14:17

Having issues getting links that match a given word to display using Xpath and domDocument. Everything seems to work up to where for($i=0;$i<$documentLinks->leng

2条回答
  •  半阙折子戏
    2020-12-18 14:28

    You can fetch the href attribute directly via XPath

    //ol/li[starts-with(@id, "stuff")]/a[contains(@href, "domain")]/@href
    

    and then just do

    foreach($result as $href){
        echo $href->nodeValue;
    }
    

    Note that contains function is case-sensitive though.

提交回复
热议问题