简体   繁体   中英

How to get the html title(header) with SimpleHTMLDom

I've used the simple_html_dom to get the a page title in head tag...I've search the solutions for my implemention...Could you give me some insparition.. any method to help me?

thanks..

The manual is pretty clear, anyway you could achieve with this code:

Given the tag <title>IANA &mdash; Example domains</title> <title>IANA &mdash; Example domains</title> you can use

include 'simple_html_dom.php';

$url = 'http://www.example.com';

$html = new simple_html_dom();

$html->load_file($url);
$title = $html->find('title',0);
echo $title->plaintext;

//output : IANA — Example domains

Plaintext will give you the content stripped of all html tags, so just...plain text. If you want the innerHtml you can use $title->innertext; instead (in this case it doesn't make any difference, but will if you have html tags within the tag you're going to fetch)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM