douzuizhuo0587 2016-11-20 13:52 采纳率: 0%
浏览 21

如果仅以特定语言翻译维基百科文章,如何提取?

How can I add a PHP conditional to the following code so that if an English wikipedia article has an Arabic version of the page (via a link on the page), then the code will retrieve the Arabic version of the article?

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <?php
    $array = array();
$myFile = "C:/Users/Public/english4.txt";

set_time_limit(0);
$array = file($myFile, FILE_IGNORE_NEW_LINES);
for ($x=0; $x<=100; $x++) {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://en.wikipedia.org/w/api.php?format=xml&prop=extracts&action=query&titles=".$array[$x]."&redirects=true");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, "Testing for http://stackoverflow.com/questions/8956331/how-to-get-results-from-the-wikipedia-api-with-php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);

//echo $result;

        $e=htmlspecialchars_decode($result);
        $eb=strip_tags($e);

     $eb=  preg_replace('~[^a-zA-Z]+~', ' ', $eb);

     $output = preg_replace('!\s+!', ' ', $eb);
       $n=str_replace("�","",$output);
       $r=substr_count($n, " ");
      if ($r>100){
      file_put_contents($x.".txt",$n);}

}
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?