#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Delhi
    Posts
    13
    Rep Power
    0

    I am trying to extract title and description but its not working


    Hello everyone

    I am trying to extract title and description using url but its not working for all url

    like

    This code is working but only for few urls
    Code:
    <?php
    
    
    $url='http://apnatimepass.com';
    preg_match("/<title>(.+)<\/title>/siU", file_get_contents($url), $matches);
    $title = $matches[1];
    
    echo "<br/>".$title."<br/>";
    
    $tags = get_meta_tags($url);
    
    // Notice how the keys are all lowercase now, and
    // how . was replaced by _ in the key.
    
    echo $tags['keywords'];     // php documentation
    echo $tags['description'];  // a php manual
      
    
    ?>
    This code extract only title

    Code:
    <?php
    
     
    $url='http://apnatimepass.com/people.php/';
    preg_match("/<title>(.+)<\/title>/siU", file_get_contents($url), $matches);
    $title = $matches[1];
    
    echo "<br/>".$title."<br/>";
    
    $tags = get_meta_tags($url);
    
    // Notice how the keys are all lowercase now, and
    // how . was replaced by _ in the key.
    
    echo $tags['keywords'];     // php documentation
    echo $tags['description'];  // a php manual
      
    
    ?>
    Could anyone help me regarding this
    Thanks
  2. #2
  3. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,101
    Rep Power
    1990
    We'd need to see the code for the get_meta_tags() function to help at all. That's what's not returning the values for you.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Delhi
    Posts
    13
    Rep Power
    0
    Originally Posted by Catacaustic
    We'd need to see the code for the get_meta_tags() function to help at all. That's what's not returning the values for you.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
     <title>   People -  List of famous people from all around the world - Apnatimepass.com </title>
    <meta name="description" content = "  People -  List of famous people from all around the world , images ,wallpapers and much more on apnatimepass.com " />
    <meta name="keywords" content=  " People -  List of famous people from all around the world , images ,wallpapers " />
    <meta property="og:title" content="  People  - Apnatimepass.com" />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="http://apnatimepass.com/people.php" />
    <meta property="og:image" content="http://apnatimepass.com/people-ms.jpg" />
    <meta property="og:site_name" content="www.apnatimepass.com" />
    <meta property="fb:admins" content="1126784815" />
    <meta itemprop="name" content="    People  - Apnatimepass.com" />
    <meta itemprop="description" content="   People -  List of famous people from all around the world , images ,wallpapers  and much more on apnatimepass.com "/>
    <meta itemprop="image" content="http://apnatimepass.com/people.php  "/>
    <link rel="shortcut icon" href="atp.jpg" />
    <link rel="stylesheet" type="text/css" href="Movie.css" />
     
     
     
     
    </head>
  6. #4
  7. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,101
    Rep Power
    1990
    Um... No. That's the pages HTML code. That's not what I meant.

    I said, we need to see the code for the get_meta_tags() function. This is a PHP function, so it will be in your PHP scripts somewhere. That's what we need to see.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    Delhi
    Posts
    13
    Rep Power
    0
    Originally Posted by Catacaustic
    Um... No. That's the pages HTML code. That's not what I meant.

    I said, we need to see the code for the get_meta_tags() function. This is a PHP function, so it will be in your PHP scripts somewhere. That's what we need to see.

    Okay, Isn't get_meta_tags() is predefined function.


  10. #6
  11. Code Monkey V. 0.9
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2005
    Location
    A Land Down Under
    Posts
    2,101
    Rep Power
    1990
    Ahhh.... Yes. Yes it is.

    I haven't used that one before, and it's a new one to me.

    From what I can see, I would assume that it could be the spaces that are in the META tags. Apart from that I am not sure.

    Code:
    <meta name="keywords" content=  " People -  List of famous people...
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    12
    Rep Power
    0
    I advice you to use some special HTML parcing libraries instead of this regular expressions.

    For example Try Simple HTML Dom Parser


    Usage example:

    PHP Code:
    // Create DOM from URL or file
    $html file_get_html('http://www.example.com/'); 
    // Find all images
    foreach($html->find('img') as $element
    echo 
    $element->src '<br>'
     
    // Find all links  
    foreach($html->find('a') as $element)    
    echo 
    $element->href '<br>'

IMN logo majestic logo threadwatch logo seochat tools logo