К основному контенту

Сообщения

Сообщения за декабрь, 2015

Нормализация пути http ссылки php. Относительный путь в абсолютный. Парсинг ссылок

/** * Created by PhpStorm. * User: x3m-bymer * Date: 13.12.2015 * Time: 13:17 */ Class Links{ /* * Извлечение ссылок из кода html */ function getLinks($html){ //Create a new DOM document $dom = new DOMDocument; @$dom->loadHTML($html); //Get all links. You could also use any other tag name here, //like 'img' or 'table', to extract other tags. $links = $dom->getElementsByTagName('a'); //Iterate over the extracted links and display their URLs $res = array(); foreach ($links as $link){ $link = $link->getAttribute('href'); if(!$link){ continue; } array_push($res, $link); } return $res; } function http_host($url){ $res = parse_url($url); if(empty($res['host'])){ return false; } return $res['host'];