Hi guys, I need a little help. I want to fetch data from another site using cURL, but I don't know how to do it using preg_match_all and how to provide output. This is the source code of the data that I want to get: <td> <b>Text</b> </td> <td> <b>Numbers here</b> </td> <td> <b>Numbers here</b> </td> Code (markup): Thanks.
Here's a quick little cURL script I threw together for you: <? // call this function, and pass it the website URL // It will return a string with the websites source function curl_page($url){ // create a new curl resource $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // grab URL, and return output $output = curl_exec($ch); // close curl resource, and free up system resources curl_close($ch); return $output; } ?> PHP: Alright, this is off the top of my head (and I always screw up the regex when I do it without testing). But this *should* work . . . if it doesn't just tinker with the regex part (the "/<td>.*<\/td>/" part). preg_match_all("/<td>.*<\/td>/", $data, $matches); var_dump($matches); PHP: Or something like that - Louis
Little modification. preg_match_all("/<td>(.*)?<\/td>/iU", $data, $matches); var_dump($matches); PHP:
Try using the DOM if you have php5 $html = $curl_response; // whatever you get from the above script, the html of the page $dom = new DomDocument(); @$dom->loadHTML($html); $tags = $dom->getElementsByTagName('td'); foreach ($tags as $tag) { if ($tag->firstChild->tagName == 'b') echo $tag->textContent; } PHP:
It was solved already. Thanks to xrvel, and I explored it a lil bit. Thanks for your responses though