Code: Select all
$link = "http://devdata.worldbank.org/external/CPProfile.asp?PTYPE=CP&CCODE=BEN";
$pattern = '#face="Verdana,Tahoma,Arial,Helvetica">([^<]*)#';
$mika = new gdp();
$mika->regex_html($link, $pattern);from the script:Array ( [0] => Array ( ) [1] => Array ( ) )
Code: Select all
$mika = new gdp();
$grr = "gdp";
$mika->mysql_select_array($grr);Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=AFG [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=AFG ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=ALB [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=ALB ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=DZA [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=DZA ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=ASM [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=ASM ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=ADO [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=ADO ) Array ( [0] => http://devdata.worldbank.org/external/C ... &CCODE=AGO [country_link] => http://devdata.worldbank.org/external/C ... &CCODE=AGO )
Code: Select all
class gdp extends databasing {
var $link;
var $regex_pattern;
var $regex_array;
//---------------------Set F(x)'s---------------//
function set_link($blink){
$this->link = $blink;
}
function set_regex_pattern($pattern){
$this->regex_pattern = $pattern;
}
function set_regex_array($list){
$this->regex_array = $list;
}
//-----------------------Get F(x)'s--------------//
function get_regex_array(){
return $this->regex_array;
}
function get_link(){
return $this->link;
}
function get_regex_pattern(){
return $this->regex_pattern;
}
//----------------------------------------other stuff
function regex_html($url,$pattern){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
// curl_setopt($ch, CURLOPTFOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
$result = curl_exec($ch);
curl_close($ch);
//$pattern='!<option value="([^"]*)">([^<]*)</option>!';
preg_match_all($pattern,$result,$ground);
//$this->set_regex_array($ground);
$this->set_regex_array($ground);
print_r($this->regex_array);
}
function mysql_select_array($database){
$this->connect();
$this->database($database);
$sql_0= "SELECT country_link FROM country_html;";
$result =mysql_query($sql_0);
$i=1;
$pattern = '#face="Verdana,Tahoma,Arial,Helvetica">([^<]*)#';
$this->set_regex_pattern($pattern);
while($row = mysql_fetch_array($result)){
print "<html>";
$this->set_link($row[0]);
print "this is link number ".$i.": ".$this->get_link()."< br>";
print "this is the pattern: ".$pattern."<br>";
print "this is the result: ";
$this->regex_html($this->get_link(),$this->regex_pattern);
$i++;
print"<br>";
}
$this->close();
}
}