PHP Get A Description Of Page

Discussion in 'PHP' started by CLMMafia, Apr 9, 2012.

  1. #1
    Hello,

    I want to get a description of a remote using PHP and CURL.

    I have used get_meta_tags, but if the site dosen't have a description meta tag it returns nothing.

    So I want a function that can get a description of a page, from the content posted on it, like what Google does.

    Thanks,
    CLM
     
    CLMMafia, Apr 9, 2012 IP
  2. mfscripts

    mfscripts Banned

    Messages:
    319
    Likes Received:
    4
    Best Answers:
    8
    Trophy Points:
    90
    Digital Goods:
    3
    #2
    There's nothing natively in php for this. You'll need to create a function to strip out the html tags (strip_tags) from the page and attempt to read the first bit of useful text. I'd imagine it would be fairly tricky to always get something useful given the first text you get back might be navigation items or site news etc.
     
    mfscripts, Apr 10, 2012 IP
  3. CLMMafia

    CLMMafia Member

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    28
    #3
    I know theres nothing in php that can do this, the only thing close too it is get_meta_tags.
    If it was as easy as adding strip_tags then I would of already done that. I know its a tricky function to create thats why I posted it on DP.
     
    CLMMafia, Apr 10, 2012 IP
  4. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Google generates snippets based on the search terms provided by the user. Since you wouldn't have such keywords to work from, I'd start by searching the <body> for <p>aragraphs that contain keywords found in the <title> tag and/or the <h1>.
     
    rainborick, Apr 10, 2012 IP
  5. Grit.

    Grit. Well-Known Member

    Messages:
    1,424
    Likes Received:
    22
    Best Answers:
    1
    Trophy Points:
    110
    #5
    You will need to look into regular expressions (regex) to manage this task. You'll need to search between the <title> tags and the meta description
     
    Grit., Apr 10, 2012 IP