HeQee

Feed Rss

PHP实现英文站在线伪原创

08.05.2011, PHP, Share, by .

 从代码中可以看出来这个是一个调用远程(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

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


无觅相关文章插件,快速提升流量