Rembrandt,
Thanks for your modified code..
rinaldos ,
The wrapper is not removing the links .. The below line in the function actually removes the links..
$summary = ereg_replace('href="/wiki/', '', $summary);
but the issue is it's not removing the links completely. Its only removing the " href="/wiki/" part and not the </a> part. For this reason it still looks like a link but not clickable..
I just found one more function to get the pure text as the output by removing all the html tags..Here I have posted the complete code.
<?php
/**
* Remove HTML tags, including invisible text such as style and
* script code, and embedded objects. Add line breaks around
* block-level tags to prevent word joining after tag removal.
*/
function strip_html_tags( $text )
{
$text = preg_replace(
array(
// Remove invisible content
'@<head[^>]*?>.*?</head>@siu',
'@<style[^>]*?>.*?</style>@siu',
'@<script[^>]*?.*?</script>@siu',
'@<object[^>]*?.*?</object>@siu',
'@<embed[^>]*?.*?</embed>@siu',
'@<applet[^>]*?.*?</applet>@siu',
'@<noframes[^>]*?.*?</noframes>@siu',
'@<noscript[^>]*?.*?</noscript>@siu',
'@<noembed[^>]*?.*?</noembed>@siu',
// Add line breaks before and after blocks
'@</?((address)|(blockquote)|(center)|(del))@iu',
'@</?((div)|(h[1-9])|(ins)|(isindex)|(p)|(pre))@iu',
'@</?((dir)|(dl)|(dt)|(dd)|(li)|(menu)|(ol)|(ul))@iu',
'@</?((table)|(th)|(td)|(caption))@iu',
'@</?((form)|(button)|(fieldset)|(legend)|(input))@iu',
'@</?((label)|(select)|(optgroup)|(option)|(textarea))@iu',
'@</?((frameset)|(frame)|(iframe))@iu',
),
array(
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
"\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0", "\n\$0",
"\n\$0", "\n\$0",
),
$text );
return strip_tags( $text );
}
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 .= $match[0][3];
$summary .= $match[0][4];
$summary .= $match[0][5];
$summary .= $match[0][6];
$summary = utf8_decode($summary);
$summary = strip_html_tags( $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;
}
?>
Please let me know if anyone have a better/efficient code ...
Thanks,
batu544