How can I get page's <title> tag's content if it can't be parsed as XML? How can I get page's <title> tag's content if it can't be parsed as XML? curl curl

How can I get page's <title> tag's content if it can't be parsed as XML?


You can use DOMDocument::loadHTML.

This will echo "The title":

<?php$doc = <<<HTML<html><head><title>The title</title><body>hhhhhhHTML;libxml_use_internal_errors(true);$d = new DOMDocument;$d->loadHTML($doc);$ts = $d->getElementsByTagName("title");if ($ts->length > 0) {    echo $ts->item(0)->textContent;}


You can use this script to get the title of a page.

# Script Title.txtvar str page, contentcat $page > $contentstex -r -c "^<title&</title&\>^" $content

Save this little code in file C:/Scripts/Title.txt. Code is in biterscripting. Start biterscripting, and enter this command.

script "C:/Scripts/Title.txt" page("http://stackoverflow.com/questions/3135488/how-can-i-get-pages-title-tags-content-if-it-cant-be-parsed-as-xml")

It will get the title of this page (the one you are viewing). Use any other URL or local file path as the value of page(). Use double quotes. When I executed this command, I got

How can I get page's <title> tag's content if it can't be parsed as XML? - Stack Overflow

You can call this script from any executable or batch file.