11/08/2018, 20:41
PHP Snippets
Get title from url $href = 'http://www.japantimes.co.jp/'; $dom = new DOMDocument(); $file = file_get_contents($href); //read url into string $dom->loadHTML($file); //load HTML $xpath = new DOMXPath($dom); $titleNode = $xpath->query('//title'); var_dump($titleNode->item(0)); ...
Get title from url
$href = 'http://www.japantimes.co.jp/'; $dom = new DOMDocument(); $file = file_get_contents($href); //read url into string $dom->loadHTML($file); //load HTML $xpath = new DOMXPath($dom); $titleNode = $xpath->query('//title'); var_dump($titleNode->item(0));
Get all link from url
$allLink = $dom->getElementsByTagName('a'); foreach($allLink as $link){ echo $link->getAttribute('href') }