本文介绍php版本的火车头采集器AI伪原创,对于网站的原创内容,站长朋友们一定很头疼。作为一个草根站长,自己写原创文章太累了。当然,我并不是说你不能写。自己写原创文章是不现实的。时间是最大的问题。
也许有的站长朋友会问:ai伪原创api,不写原创文章,如何获得更好的排名网站呢?
其实不光是我们,国内几大门户网站也不都是原创文章。他们还利用其他平台的内容进行修改,然后更改标题,从而成为他们自己的“新闻”。
<?php
header("Content-type: text/html; charset=gb2312");
set_time_limit(0);
error_reporting(E_ALL);
ini_set('display_errors', '1');
define ("CUR_DIR", '../');
define('TITLE_SEPAR', 'xxxxx');
// 这里是你的API地址
define('API_URL', 'http://api.xiaofamao.com/api.php?json=0&v=2&key=yuyu');
// 待执行目录
define('CUR_FOLDER', CUR_DIR.'word');
// 执行后保存目录
define('DEST_FOLDER', CUR_DIR.'xiaofamao');
// 执行后保存目录 失败
define('DEST_FOLDER_FAIL', CUR_DIR.'xiaofamao_fail');
$one_file = get_one_file();
// 判断是否还有任务
if (!$one_file){
echo PHP_EOL.'* 任务数为0, 程序已退出';
exit;
}
while ($one_file) {
echo PHP_EOL.'* 正在执行:' . PHP_EOL. file_path($one_file);
echo PHP_EOL.'* 请耐心等候...';
$data_arr = get_contents_filter(file_path($one_file));
$title = $data_arr['title'];
$title_src = $data_arr['title'];
$content = $data_arr['content'];
$content = replace_shuminghao($content);
$content = get_utf8_data($content);
$new_content = curl_request(API_URL, array('wenzhang'=>$content));
$new_content = get_gbk_data($new_content);
$new_content = restore_shuminghao($new_content);
#var_dump($new_content);
$new_content = content_format($new_content);
$new_content = $new_content;
#$new_title = get_ai_title($title);
$title = get_utf8_data($title);
$new_title = $title;
//$new_title =curl_request(API_URL, array('wenzhang'=>$title));
//$new_title = get_gbk_data($new_title);
#echo $new_title;
# 如果标题伪原创成功
if ($new_title === 'xx'.$title) {
$new_title = get_gbk_data($title);
//save_new_file(DEST_FOLDER_FAIL.DIRECTORY_SEPARATOR.$new_title.'.txt', $new_content);
save_new_file(DEST_FOLDER_FAIL.DIRECTORY_SEPARATOR.$title_src.'.txt', $new_content);
}
else {
$new_title = strip_tags($new_title);
$new_title = str_replace(':', ":", $new_title);
$new_title = str_replace('?', "?", $new_title);
$new_title = str_replace(array('*','"','<','>','|'),'_', $new_title);
$new_title = get_gbk_data($new_title);
#$title = get_gbk_data($title);
#save_new_file(DEST_FOLDER.DIRECTORY_SEPARATOR.$new_title.'.txt', $new_content);
save_new_file(DEST_FOLDER.DIRECTORY_SEPARATOR.$title_src.'.txt', $new_content);
#save_new_file(DEST_FOLDER.DIRECTORY_SEPARATOR.$new_title.'.txt', $content);
}
//
//
#save_new_file(DEST_FOLDER.DIRECTORY_SEPARATOR.$title.'.txt', $new_content);
file_ok($one_file);
//show_info_gb2312('伪原创结果:'.PHP_EOL. $final_data);
//save_new_file(DEST_FOLDER.DIRECTORY_SEPARATOR.$new_title, $new_content);
//var_dump($final_data);
// sleep(3);
$one_file = get_one_file();
// show_reflesh();
}
show_info_gb2312(PHP_EOL.'任务完成'.PHP_EOL);
function replace_shuminghao($content) {
$content = str_replace('![](', '<(', $content);
$count = preg_match_all("/<\((.*?)\)/", $content, $matches);
#var_dump($matches[0]);
if (isset($matches[0][0]))
{
foreach ($matches[0] as $key => $value) {
#echo $value;
$new_val = '《'.$matches[1][$key].'》';
$content = str_replace($value, $new_val, $content);
}
}
#echo $content;
return $content;
}
function restore_shuminghao($content) {
$count = preg_match_all("/《http(.*?)》/", $content, $matches);
#var_dump($matches[0]);
if (isset($matches[0][0]))
{
foreach ($matches[0] as $key => $value) {
$new_val = '![](http'.$matches[1][$key].')';
$content = str_replace($value, $new_val, $content);
}
#return $matches[0];
}
return $content;
}
function content_rewrite($content) {
$data = curl_request(API_URL, array('wenzhang'=>$content));
return $data;
}
function content_format($data) {
$data = fix_newline($data);
$data_arr = explode(PHP_EOL, $data);
$ret_str = '';
foreach($data_arr as $key => $value) {
#echo $value;
$ret_str .= ' '.$value.PHP_EOL.PHP_EOL;
#$ret_str .= 'bbbbbbbbbbbbbbbbbb';
}
return $ret_str;
}
function title_content_rewrite($title, $content) {
$article_src = $title.TITLE_SEPAR.PHP_EOL.$content;
$data = curl_request(API_URL, array('wenzhang'=>$article_src));
$data = str_replace("Xx", "xx", $data);
$data = str_replace("\n", "\r\n", $data);
$data = str_replace("<p>\r\n", "<p>", $data);
$data = ltrim($data);
#var_dump($data);
$temp = explode(TITLE_SEPAR, $data);
#var_dump($temp);
$temp[0] = trim($temp[0]);
$temp[1] = ltrim($temp[1]);
$temp[1] = ltrim($temp[1], '</p>');
$temp[1] = ltrim($temp[1]);
$temp[1] = ltrim($temp[1]);
return $temp;
}
function show_info($str) {
echo '<p>' . $str . '</p>';
}
function get_utf8_data($data) {
$encode = mb_detect_encoding($data, array('ASCII', 'UTF-8', 'GB2312', 'GBK','BIG5'));
if ($encode !== 'UTF-8') {
//show_info_gb2312('文件非 UTF-8,正在转成UTF-8');
$utf8_data = iconv($encode, 'UTF-8//IGNORE', $data);
return $utf8_data;
}
return $data;
}
function get_gbk_data($data) {
$encode = mb_detect_encoding($data, array('ASCII', 'UTF-8', 'GB2312', 'GBK','BIG5'));
if ($encode === 'UTF-8') {
//show_info_gb2312('文件非 UTF-8,正在转成UTF-8');
$gbk_data = iconv('UTF-8//IGNORE', 'GBK//IGNORE', $data);
return $gbk_data;
}
return $data;
}
function get_ai_title($title) {
$title = urlencode($title);
return curl_request($url);
}
function show_info_gb2312($string) {
echo get_gbk_data($string);
newline();
}
function get_img_arr($array) {
$ret_arr = array();
foreach ($array[1] as $key => $value) {
if (stripos($value, 'C:\\') === 0) {
$ret_arr[0][] = $value;
}
else {
$ret_arr[1][] = $value;
}
}
asort($ret_arr);
return $ret_arr;
}
function str_replace_once($search, $replace, $subject) {
$firstChar = strpos($subject, $search);
if($firstChar !== false) {
$beforeStr = substr($subject,0,$firstChar);
$afterStr = substr($subject, $firstChar + strlen($search));
return $beforeStr.$replace.$afterStr;
} else {
return $subject;
}
}
//var_dump(str_replace_once('**x**', 'xxxxxxxxxx', 'aaa**x**bbb'));
//exit;
function put_img_arr($array, $string) {
$string = str_replace('**X**', '**x**', $string);
foreach ($array as $key => $value) {
$string = str_replace_once('**x**', $value, $string);
}
return $string;
}
function get_rewrite_title($data) {
// var_dump($data);
$data = reset_newline($data);
$data_arr = explode(PHP_EOL, $data);
$title = str_replace(array('<P>', '<p>'), array('',''), $data_arr[0]);
array_shift($data_arr);
$contents = '<p>'.implode(PHP_EOL, $data_arr);
$new_arr = array($title, $contents);
return $new_arr;
}
/*
foreach ($news_list as $key => $value) {
echo $value."<br>".PHP_EOL;
$value = iconv("utf-8", "gb2312", $value);
$data = file_get_contents($value);
$data = iconv("GBK", "utf-8", $data);
// echo $data;
$data = rewrite($data);
$data = str_replace("\r\n", "\n", $data);
$data = str_replace("\r", "\n", $data);
$data = str_replace("\n", "\r\n", $data);
sleep(2);
$data = auto_typeset($data);
save_new_file('b'.$value, $data);
}
*/
function auto_typeset($data) {
$data = str_replace(
array('<P>'."\r\n", '<P>', '<p>'),
array('<p>', '<p>', '<p> '),
$data
);
return $data;
}
function rewrite($article) {
$url = API_URL;
return curl_request($url, array('wenzhang'=>$article ));
}
function save_new_file($filename, $data) {
if (! data_exists($filename)) {
file_put_contents($filename, $data);
}
}
// 缓存数据是否存在
function data_exists($filename) {
$filename = str_replace('\\','/', $filename);
// var_dump($filename);
// var_dump(dirname($filename));
if (!is_dir(dirname($filename))) {
// echo 'aaaaaaaaaaa';
mkdir(dirname($filename),0755,true);
}
// var_dump(dirname(dirname($filename)));
if (!is_dir(dirname(dirname($filename)))) {
// echo 'bbbbbbbbbb';
mkdir(dirname(dirname($filename)),0755,true);
}
if (file_exists($filename)) {
return true;
}
return false;
}
function get_news_list($floder) {
$news_list = array();
if($handle = opendir($floder)){
while (false !== ($file = readdir($handle))){
//$dir = iconv("utf-8", "gb2312", $file);
$file = iconv("gb2312", "utf-8", $file);
if ($file !== '..' && $file !== '.')
{
$news_list[] = $floder.DIRECTORY_SEPARATOR.$file;
}
// echo "$file\n";
}
closedir($handle);
}
return $news_list;
}
//参数1:访问的URL,参数2:post数据(不填则为GET),参数3:提交的$cookies,参数4:是否返回$cookies
function curl_request($url,$post='',$cookie='', $returnCookie=0){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
if (ini_get('open_basedir') == '' && strtolower(ini_get('safe_mode')) != 'on'){
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
}
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
curl_setopt($curl, CURLOPT_REFERER, "http://XXX");
if($post) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));
}
if($cookie) {
curl_setopt($curl, CURLOPT_COOKIE, $cookie);
}
curl_setopt($curl, CURLOPT_HEADER, $returnCookie);
curl_setopt($curl, CURLOPT_TIMEOUT, 150);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($curl);
if (curl_errno($curl)) {
return curl_error($curl);
}
curl_close($curl);
if($returnCookie){
list($header, $body) = explode("\r\n\r\n", $data, 2);
preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches);
$info['cookie'] = substr($matches[1][0], 1);
$info['content'] = $body;
return $info;
}else{
return $data;
}
}
// 计算中文字符串长度
function utf8_strlen($string = null) {
// 将字符串分解为单元
preg_match_all("/./us", $string, $match);
// 返回单元个数
return count($match[0]);
}
function get_one_file() {
$arr_all = get_all_files();
#var_dump( $arr_all );
$arr_ok = get_ok_files();
//var_dump($arr_ok);
foreach($arr_all as $v) {
if (array_search($v, $arr_ok)===false) {
return $v;
}
}
return false;
}
function get_all_files() {
return listDir(CUR_FOLDER);
}
function get_ok_files() {
//var_dump(CUR_DIR.'ok.txt');
$data = file_get_contents(CUR_DIR.'ok.txt');
$data = str_replace("\xef\xbb\xbf", '', $data);
$data_arr = explode(PHP_EOL, $data);
return $data_arr;
}
function file_ok($file_name) {
file_put_contents(CUR_DIR.'ok.txt', $file_name.PHP_EOL, FILE_APPEND);
}
function listDir($dir)
{
// echo $dir;
$reta = array();
if(is_dir($dir))
{
if ($dh = opendir($dir))
{
while (($file = readdir($dh)) !== false)
{
if((is_dir($dir."/".$file)) && $file!="." && $file!="..")
{
//echo 'aa';
//$file = iconv("gb2312", "utf-8//IGNORE", $file);
// $file = ConvertToUTF8($file);
#$file = mb_convert_encoding($file, 'UTF-8', 'GBK');
$reta[] = $file;
// echo "<b><font color='red'>文件名:</font></b>",$file,"<br><hr>";
listDir($dir."/".$file."/");
}
else
{
if($file!="." && $file!="..")
{
// echo $file."<br>";
if (stripos($file, '.txt')!==false) {
#$file = iconv("GBK", "utf-8//IGNORE", $file);
// echo $file.'<br>';
$reta[] = $file;
}
}
}
}
closedir($dh);
}
}
//var_dump($reta);
return $reta;
}
function file_path($filename) {
return CUR_FOLDER.DIRECTORY_SEPARATOR.$filename;
}
function short_filename($filename) {
$filename = str_replace(CUR_FOLDER.DIRECTORY_SEPARATOR, '', $filename);
$filename = str_replace('.txt', '', $filename);
return $filename;
}
function get_contents_filter($file_name) {
$file_name = get_gbk_data($file_name);
// $file_name = mb_convert_encoding($file_name, 'UTF-8', 'ISO-8859-15');
/// $file_name = iconv("utf-8", "GBK//IGNORE", $file_name);
// echo $file_name.'<br>';
$data = file_get_contents($file_name);
$data = get_gbk_data($data);
$data = str_replace("\t", '', $data);
// 优化换行符
$data = fix_newline($data);
$data_title = short_filename($file_name);
//var_dump(get_utf8_data($data));
return array('title'=>$data_title, 'content'=>$data);
}
function fix_newline($data) {
$data = str_replace("\r", "\n", $data);
while(strpos($data, "\n\n") !== false) {
$data = str_replace("\n\n", "\n", $data);
}
$data = str_replace("\n", PHP_EOL, $data);
return $data;
}
function show_reflesh() {
$str = '<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout("myrefresh()",1000);
</script>';
echo $str;
}
function after ($this, $inthat)
{
if (!is_bool(strpos($inthat, $this)))
return substr($inthat, strpos($inthat,$this)+strlen($this));
};
function after_last ($this, $inthat)
{
if (!is_bool(strrevpos($inthat, $this)))
return substr($inthat, strrevpos($inthat, $this)+strlen($this));
};
function before ($this, $inthat)
{
return substr($inthat, 0, strpos($inthat, $this));
};
function before_last ($this, $inthat)
{
return substr($inthat, 0, strrevpos($inthat, $this));
};
function between ($this, $that, $inthat)
{
return before ($that, after($this, $inthat));
};
function between_last ($this, $that, $inthat)
{
return after_last($this, before_last($that, $inthat));
};
// use strrevpos function in case your php version does not include it
function strrevpos($instr, $needle)
{
$rev_pos = strpos (strrev($instr), strrev($needle));
if ($rev_pos===false) return false;
else return strlen($instr) - $rev_pos - strlen($needle);
};
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
if (strpos($file, '.txt') === false) {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
}
closedir($dir);
}
function ConvertToUTF8($text){
$encoding = mb_detect_encoding($text, mb_detect_order(), false);
if($encoding == "UTF-8")
{
$text = mb_convert_encoding($text, 'UTF-8', 'UTF-8');
}
$out = iconv(mb_detect_encoding($text, mb_detect_order(), false), "UTF-8//IGNORE", $text);
return $out;
}
function newline() {
echo PHP_EOL;
}
function sanitizeUTF8($value)
{
if (self::getIsIconvEnabled()) {
// NEW ----------------------------------------------------------------
$encoding = mb_detect_encoding($value, mb_detect_order(), false);
if($encoding == "UTF-8")
{
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
}
$value = iconv(mb_detect_encoding($value, mb_detect_order(), false), "UTF-8//IGNORE", $value);
// --------------------------------------------------------------------
// OLD --------------------------------------
// $value = @iconv('UTF-8', 'UTF-8', $value);
// -------------------------------------------
return $value;
}
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
return $value;
}
?>
有朋友问我,这样做网站会被K吗?是作弊吗?
就这个问题,我想发表一下我个人的看法,供大家参考。搜索引擎毕竟是机器,在抓取一篇文章后,它们会将其与数据库中的现有文章进行比较。如果他们发现一篇文章相似度很高,就会被认为是抄袭,否则就会被认为是原创。
当然,如果照搬的话,那就一定是抄袭了。使用AI伪原创工具转换不仅仅是将文章内容转换为同义词,而是通过AI技术根据文章内容重新创建,并根据文章的结构和内容重新创建。文章发生了彻底的改变。如果搜索引擎抓取到它,它就被认为是原创文章。所以您可以放心使用。