Return to Snippet

Revision: 61687
at January 5, 2013 22:34 by goo


Initial Code
function get_url_title( $url ){
	try{
		$doc = new DOMDocument();
		@$doc->loadHTMLFile( $url );
		$xpath = new DOMXPath( $doc );
		$title = $xpath->query( '//title' );
		$title = $title->item( 0 );
		if( !( isset( $title->nodeValue ) ) ){
			return $url;
		}
		$title = $title->nodeValue;
		if( is_string( $title ) ){
			return $title;
		}
		return $url;
	}catch (Exception $e) {
		return $url;
	}
}

Initial URL

                                

Initial Description
Return URL Title.
Return URL if any problem.

Initial Title
[PHP] Get URL Title

Initial Tags
url, php

Initial Language
PHP