命令行版本的中英互译,调用了百度翻译api。
$en how are you
how -> 怎么用
are -> 是
you -> 你
$en "how are you"
how are you -> 好好学习,天天向上
$en 好好学习,天天向上
好好学习,天天向上 -> study hard and make progress every day
需要php-cli支持:
sudo yum install php-cli
需要赋予执行权限:
chmod a+x en
#!/bin/php
<?php
$url = 'http://openapi.baidu.com/public/2.0/bmt/translate?client_id=T8Qlsxu4VmLt6qWbqqjtMdLo&q=';
isset($argv[1]) or die('至少指定一个词作为参数'.PHP_EOL);
$q = $argv;
array_shift($q);
foreach($q as $k=>$v){
$q[$k]= urlencode($v);
}
$json = file_get_contents($url.implode('%0A',$q));
$arr=json_decode($json,true);
$arr = $arr['trans_result'];
foreach ($arr as $key) {
$cmd='echo -ne"e[44;37;5m '.$key['dst'].' 33[0m"';
echo"${key['src']} ->".exec($cmd);
echo PHP_EOL;
}
?>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号