全方位站长技能、SEO优化学习平台
当前位置:网站首页 > PHP笔记 > 正文

php利用百度翻译和反翻译做一个文章伪原创工具

作者:admin发布时间:2023-12-24分类:PHP笔记浏览:118评论:0


温馨提示:手机扫码可阅读当前文章!
文章简介:百度翻译每个月免费100万字,为了不浪费,我们应该用来做什么呢?难道每有什么用吗?当然有用了。今天我们做一个利用百度的翻译功能做一个伪原创工具。原理很简单:1、中文-->英文-->中文2、中文-->英文-->中英文组...

百度翻译每个月免费100万字,为了不浪费,我们应该用来做什么呢?难道每有什么用吗?当然有用了。今天我们做一个利用百度的翻译功能做一个伪原创工具。原理很简单:


php利用百度翻译和反翻译做一个文章伪原创工具  第1张

1、中文-->英文-->中文

2、中文-->英文-->中英文组合


看懂了吧,就是吧我们复制的内容首先翻译成英文,然后在通过百度翻译把英文内容翻译成中文就起到伪原创的效果了。当然还有一种,就是把中文翻译成英文,然后一段中文掺杂一段英文,也能起到伪原创的效果!


废话不多说了,直接上刺刀:

<?php
if(count($_POST)==0){//POST数据不为空执行的代码
$text_0='输入您要翻译或者伪原创的内容。';
}else{
$query=$_POST['text'];
$wyc_sx=$_POST['wyc'];
$text_0=$query;
$query = nl2br($query);//将分行符"\r\n"转义成HTML的换行符
$query = str_replace("/>",'',$query);
$query = str_replace("<br",'<br/>',$query);
$query=explode(" ",$query);///转换成数组
$from='zh';
$to='en';
$domain='novel';

if($query==null){
$max=0;    
}else{
$max=count($query);    
}//得出循环次数

for ($i=0; $i<=$max; $i++)
{
$q["$i"]= nl2br($query["$i"]);
$q["$i"] = str_replace("<br />",'',$q["$i"]);
$q["$i"] = str_replace("<br/>",'',$q["$i"]);
if(strlen($q["$i"])>='2'){
$url1="https://www.xszi.net/zb_users/visitors/baidu.php?q=".$q["$i"].'&mid=1&keyw='.$keys;
usleep(150);
$data1= file_get_contents($url1);
$txt=$txt.$data1;//英文内容
$txt_hb=$txt_hb.$q["$i"].'<br/>'.$data1;//中英混编//
//$data= str_replace("<br/>",'',$data1);
//$url2="https://www.xszi.net/zb_users/visitors/baidu.php?q=".$data."&mid=2";
//$data2= file_get_contents($url2);
$txt_wyc=$txt_wyc.$data2;//通过英文内容反向翻译,达到伪原创的目的
usleep(150);
}
}
}//POST数据不为空执行的代码
$wyctitle='输出内容:';   
if($wyc_sx=='1'){
$wyctitle='中->英内容:';  
}
if($wyc_sx=='2'){
$wyctitle='中英混编内容:';  
$txt=$txt_hb;
}
if($wyc_sx=='3'){
$txt=$txt_wyc;
$wyctitle='中文->中文伪原创内容:';    
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>文章翻译/(伪原创) - 小松子博客</title>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<style type="text/css">
        body {
            height: 100%;width: 100%;
            background: url("html/img/bg_tj.png");
            background-size:cover;
        }
table.imagetable {
    font-family: verdana,arial,sans-serif;
    font-size:11px;
    color:#333333;
    border-width: 1px;
    border-color: #999999;
    border-collapse: collapse;
}
table.imagetable th {
    background:#b5cfd2 url('cell-grey.jpg');
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #999999;
}
table.imagetable td {
    background:#dcddc0 url('cell-grey.jpg');
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #999999;
}
</style>

<!-- Table goes in the document BODY -->
</head>
<body>
     <form  method="post" action="">
      <table style="width:100%;">
                    <tr><th>百度翻译功能<select name ="wyc">
    <option value="2">下拉选择翻译方式</option>
<option value="1">中->英</option>
<option value="2">中英混合</option>
<option value="3">伪原创内容</option>
</select></th></tr>
                </thead>
                <tbody>
<!-- CSS goes in the document HEAD or added to your external stylesheet -->
<tr>
<td style="text-align:center;background-color:#CCCCCC;">

<p style="display:none;"><label for="txaArticle">内容(*)</label></p>
<p><textarea name="text" id="text" cols="50" rows="4" tabindex="5" placeholder="<?=$text_0?>" style="width:100%;height:300px;"></textarea></p>
<p><input name="sumbit" type="submit" tabindex="6" value="提交" /></p>
</form>
</tr>
<tr><td><?=$wyctitle?><hr><?=$txt?>
</td></tr>
                          </tbody>
            </table>
</body>
</html>

这组代码我们保存在baidufanyi.php这个文件例。这里起到对我们的文字进行隔段隔行分割的作用。

最重要的作用来了。

<?
$q=strip_tags($_GET['q']);
$mid=strip_tags($_GET['mid']);
if($mid==1){
$from='zh';
$to='en';    
}elseif($mid==2){
$to='zh';
$from='en';
}else{
exit;
}

$id="***"; //去百度申请
$key="****";//去百度申请
$domain='novel';
//----------------------
$salt=rand(100000,999999);
$sign=$id.$q.$salt.$domain.$key;
$sign=md5($sign);
$url="http://api.fanyi.baidu.com/api/trans/vip/fieldtranslate?q=".$q."&from=".$from."&to=".$to."&appid=".$id."&salt=".$salt."&domain=".$domain."&sign=".$sign;
$file_contents= file_get_contents($url);
$data = json_decode($file_contents, true);
//$data=array_values($data);
$error=$data['error_code'];
$error_msg=$data['error_msg'];
if($error!=null){
echo '错误代码:'.$error.'->错误信息:'.$error_msg.'<br/>';
}else{
$text=$data['trans_result'][0]['dst']; 
$text = str_replace("_",'',$text);
echo $text.'<br/>';
}
?>

这组代码是将我们分割好的文字,按行翻译成英文。然后再和我们分隔好的中文组合,变成中英混编的功能!借此达到伪原创的效果!我们把这个文件命名为baidu.php!



欢迎您,来自美国的朋友,您的IP:3.139.87.15,您的网络:Amazon_EC2服务器


欢迎 发表评论:

  • 请填写验证码
PHP笔记排行
随机推荐
猜你喜欢

服务热线

1888888888

要发发发发发发

站长微信公众号

站长微信公众号

分享:

支付宝

微信