Jump to content

Need help extracting strings from webpages using cURL. Where is my code wrong?


Lexicon

Recommended Posts

I'm trying to work on my php skills by creating an online content "finder". I'm using cURL to grab webpage HTML and store it in a variable.

 

I then want my program to find the article title, keywords and the content. I'm using articles from Ezine.

 

here is an example webpage.

 

http://ezinearticles.com/?8-Ways-to-Reduce-Stock-Investment-Risks&id=954266

 

I don't have any problems grabbing the webpage html. But when I try to grab the title, keywords, and content using this code.

 

$title = getbetween($html, "<title>", "</title>");
$keywords = getbetween($html, "<meta name=\"keywords\" content=\"", "\">");
$content  = getbetween($html, "<div id=\"body\">", "</div>");
$content  = "<P>" . getbetween($content . "<E>", "<P>", "<E>");

echo "Title: " . $title . "<P>";
echo "Keywords: " . $keywords . "<P>";
echo "Content: " . $content . "<P>";

 

Only the title comes out of the page, the rest of the values are blank... I'm not sure why the getbetween is only working to extract the title from the html. Does anyone have any ideas why??

 

I tried testing to see if it was grabbing the propper webpage and when I used 'echo $html;' the webpage came out fine on my page..

 

I am totally lost on this, I just want to practice using cURL and my webrequest coding.

 

Thanks for any help, I appreciate it.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.