从代码中可以看出来这个是一个调用远程(http://semthinking.com/rewrite/index.php)的一个函数,写下来放给需要的同学。
<?php
/*
* 实现英文伪原创
*/
function rewrite($article,$test = 0,$level = 3,$percent = 10){
$url = 'http://semthinking.com/rewrite/index.php' ;
$fields = array(
'article'=>urlencode($article) ,
'level'=>urlencode($level) ,
'percent'=>urlencode($percent) ,
'test'=>urlencode($test) ,
'submit'=>urlencode("Rewrite now") ,
);
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&' ;
}
rtrim($fields_string ,'&') ;
$ch = curl_init() ;
curl_setopt($ch, CURLOPT_URL,$url) ;
curl_setopt($ch, CURLOPT_POST,count($fields)) ;
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string) ;
ob_start();
curl_exec($ch);
$result = ob_get_contents() ;
ob_end_clean();
preg_match_all("'<hr size\=1>(.*)<script'isU",$result,$rewrited);
$rewrited = $rewrited[1][0] == '' ? $article : $rewrited[1][0];
return $rewrited;
}
?>
使用实例如下
<?php //定义一个待处理字符串 $article = <<<END Protect your loved ones in Carnia by joining the adventure! What would it take to change a warrior's destiny? The Big Adventure! Inotia3: Children of Carnia! An inevitable fate lies before the children of Carnia. The greatest epic adventure by far! The Chronicles of Inotia 3! The new legend is about to begin in the continent of Inotia. "With the coming of age ritual ahead, Lucio and Ameli from Carnia village happen to be acquiring guntlets, and the adventure stirred up by these guntlets leads to a consequence that is a way beyond their imaginations... Lucio and Ameli realize soon that they have extraordinary destinies lain before them... Warriors' fates have been predestined for thousands of years already... Will those who are born to be warriors be happy after all? END; //测试高亮替换字符 //echo rewrite($article,1); //显示替换后的内容 echo rewrite($article); ?>
声明: 本站遵循 署名-非商业性使用-相同方式共享 3.0 共享协议.转载请注明转自 HeQee