Posted By

goo on 01/05/13


Tagged

url php title


Versions (?)

[PHP] Get URL Title


 / Published in: PHP
 

Return URL Title. Return URL if any problem.

  1. function get_url_title( $url ){
  2. try{
  3. $doc = new DOMDocument();
  4. @$doc->loadHTMLFile( $url );
  5. $xpath = new DOMXPath( $doc );
  6. $title = $xpath->query( '//title' );
  7. $title = $title->item( 0 );
  8. if( !( isset( $title->nodeValue ) ) ){
  9. return $url;
  10. }
  11. $title = $title->nodeValue;
  12. if( is_string( $title ) ){
  13. return $title;
  14. }
  15. return $url;
  16. }catch (Exception $e) {
  17. return $url;
  18. }
  19. }

Report this snippet  

You need to login to post a comment.