Hi,
I tried the same code in my local machine and it worked fine.. but in the server, it not working.. and I think this is because of allow_url_fopen option is off .. this is just a guess and I think ini_set is not working with my host..
so, I tried some other way to bypass this thing and now its working..
but now the problem is all the internal links are not working ..
Is there anyway to remove those internal links .. ?? I don't want those internal links and if possible <p> </P> tags also in the output...
rinaldos,
here is my get_wiki_cat function..
function get_wiki_cat($cat_name) {
global $user_info, $site_db, $session_info, $config;
ini_set('user_agent', '(Windows; U; Windows NT 6.1; de; rv:1.9.2) Gecko/20100115 Firefox/3.6');
$sign = array('#', '?', '§', '$', '%', '&', '/', '(', ')', '=', '^', '°', '*', '@', ' ');
$cat_name = str_replace($sign,"_",$cat_name);
if(!$cat_name) return false;
//The whole test from the API take Wiki
if (!ini_get('allow_url_fopen') && !ini_get('allow_url_include'))
{
# Force allow_url_fopen=on and allow_url_include=off
stream_wrapper_unregister('http');
require('http_wrapper.php');
stream_wrapper_register('http', 'moo_stream_wrapper_http');
}
$url = "http://en.wikipedia.org/w/api.php?format=xml&action=parse&page=".$cat_name;
$xml = simplexml_load_file($url);
$text = $xml->parse->text;
if(!$text) return false;
//Search summary
$reg_exp = '/<p>(.*?)<\/p>/s';
preg_match_all($reg_exp, $text, $match);
$summary = $match[0][0];
$summary .= $match[0][1];
$summary .= $match[0][2];
$summary = utf8_decode($summary);
$summary .= "<a href = 'http://en.wikipedia.org/wiki/$cat_name'>Source: Wikipedia</a>";
//If item is not available
if($summary == "<p><b>Article content ??</b></p>") return false;
//Links to internal pages
$summary = ereg_replace('href="/wiki/', '', $summary);
return $summary;
}