Looking for php libary that correct url`s of a html page -
this question has answer here:
- how parse , process html/xml in php? 27 answers
i'm making kind of proxy. php script downloads webpage , shows downloaded content. output doesn't original webpage because url's needs corrected (css, links, images, etc). i'm looking libary gets html elements src
, href
attributes can change value. example:
<link href="/images/favicon.ico">
needs changed to
<link href="http://example.com/images/favicon.ico">
what best way this?
<?php require_once('controller/simple_html_dom.php'); $str = '<link rel="stylesheet" type="text/css" href="/css/normalize.css?stillnospring"/> <script type="text/javascript" src="/js/heyoffline.js?stillnospring"></script>'; $html = str_get_html($str); foreach($html->find('link[rel=stylesheet]') $stylesheets) { echo $stylesheets->getattribute('href')."<br/>"; } foreach($html->find('script[type=text/javascript]') $scripts) { echo $scripts->getattribute('src')."<br/>"; } ?>
you following links
/css/normalize.css?stillnospring /js/heyoffline.js?stillnospring
Comments
Post a Comment