Jump to content

curl output manipulation


rhock_95

Recommended Posts

can someone direct me to a source or explain how to get specific content from a page returned from a curl script?...i.e. if the page submits a word (via curl ) to a dictionary site...how can I get get just the requested content in the output display?

 

do I have to strip everything or is is there a way to just grab the targeted content without retriving and stripping the rest of the page (images, text etc etc)

Link to comment
https://forums.phpfreaks.com/topic/75031-curl-output-manipulation/
Share on other sites

You'll need to set the curl option RETURNTRANSFER to 1 to get the contents in a string. e.g:

 

<?php
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,'your website');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
//other curl options
$result = curl_exec($ch);

 

You'll then need to use some regular expressions on the returned string, $result, to find the data you need. Theres a subforum on this site for regular expressions, or try looking in the manual: preg_match()

 

On a side note, some dictionary sites do offer an API, which would possibly be an easier way to go. A quick google shows that urbandictionary.com does, but take a look for the one you want.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.