Get the inner text using curl concept in php

前端 未结 5 1619
情深已故
情深已故 2021-01-25 15:18

This is html text in the website, i want to grab

1,000 Places To See Before You Die

5条回答
  •  情深已故
    2021-01-25 15:44

    Why not DOMDocument and get title attribute?:

    $string = '
    • 1,000 Places To See Before You Die 2009
    • '; $dom = new DOMDocument; $dom->loadHTML($string); $xpath = new DOMXPath($dom); $text = $xpath->query('//ul[@class="listings"]/li/a/@title')->item(0)->nodeValue; echo $text;

    or

    $text = explode("\n", trim($xpath->query('//ul[@class="listings"]/li/a')->item(0)->nodeValue));
    echo $text[0];
    

    Codepad Example

提交回复
热议问题