Forum Moderators: coopster

Message Too Old, No Replies

Parsing an results file from remote site.

         

marcusb

2:25 pm on Sep 22, 2003 (gmt 0)



I am using curl to generate a results page from jobserve and want to extract the number of posted jobs from this page. This appears in a text string as follows.

Results 1-20 of 474 Matching Jobs

I want to extract the number appearing between "of" and "matching" using preg_match. can anyone give me some pointers. I can call the page fine but can't extract the number string.

code below
>>>>>>>>>>>>>>>>>>

<?php
$ch = curl_init ("http://www.jobserve.com/IT/jobserve/searchresults.asp?jobType=C&d=7&page=1&q=java+uk");
//$fp = fopen ("java.txt", "w");
//curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);

$output = curl_exec ($ch);
curl_close ($ch);
//fclose ($fp);
//
preg_match ("/(Results)?(Matching)/", $output, $answer);
$jumps = $answer;
// strip it to the last few digits
preg_match("/(of)?+/", $jumps, $hosts);
echo $hosts;
?>

coopster

4:03 pm on Sep 22, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



preg_match("/of (\d+) Matching/", $string, $matches);
$jumps = $matches[1];