在线检测文章原创度工具

日期:2020-02-21 人气:307 来源:原创

本工具需要在PHP环境下运行,建议PHP7.0,可以做成API可以对接软件使用。

本工具作者:念忘

代码如下:


<?php

header('Content-type:text/html;charset=utf-8');

error_reporting(0);




//判断是否为群友

$t=$_GET['token']??'';

if($t!='这里填写自己的QQ群号'){

echo '权限不够请加群';

exit;

}


if(!$_POST['info']){

echo '别逗,浏览器直接打开只能看到这个。对你没看错!!!';

exit;

}



$content=ClearHtml($_POST['info']);

$str=mb_strlen($content, 'UTF-8');

if($content && $str> 100 ){

$ycl=ycl($content);

echo json_encode($ycl,JSON_UNESCAPED_UNICODE);

}else{

echo json_encode(['ycl'=>'0','info'=>'这是一篇文章吗?字数好像有点少啊!','content'=>array()],JSON_UNESCAPED_UNICODE);

}

function curl($url,$header=0,$cookie=0,$referer=0,$ua=0,$nobaody=0){

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$url);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$httpheader[] = "Accept:*/*";

$httpheader[] = "Accept-Encoding:gzip,deflate,sdch";

$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";

$httpheader[] = "Connection:close";

curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);

if($header){

curl_setopt($ch, CURLOPT_HEADER, TRUE);

}

if($cookie){

curl_setopt($ch, CURLOPT_COOKIE, $cookie);

}

if($referer){

curl_setopt($ch, CURLOPT_REFERER, $referer);

}

if($ua){

curl_setopt($ch, CURLOPT_USERAGENT,$ua);

}else{

curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3314.0 Safari/537.36 SE 2.X MetaSr 1.0');

}

curl_setopt($ch, CURLOPT_ENCODING, "gzip");

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

$ret = curl_exec($ch);

curl_close($ch);

return $ret;

}




function bdycl($content){


$info=curl('https://www.baidu.com/s?ie=utf8&wd='.urlencode($content).'&rn=10');

preg_match_all("/<div class=\"c-abstract\">(.*?)<\/div>(.*?)href=\"(.*?)\"/is", $info,$baidu);//匹配出信息


 $count1=count($baidu['1']);

for($i=0;$i<$count1;$i++){

preg_match_all("/<em>(.*?)<\/em>/is", $baidu['1'][$i],$baidu_em);

$count=count($baidu_em[1]);

//echo $i.$baidu['1'][$i].PHP_EOL;

if($count>1){

$baiduem='';

foreach($baidu_em[1] as $value){

$baiduem.=$value;

}

$bdem[]=[

'content'=>$baiduem,

'url'=>$baidu['3'][$i]

];

}else{

$bdem[]=[

'content'=>@$baidu_em[1][0],

'url'=>$baidu['3'][$i]

];

}

}


if(is_array($bdem)){

$count=count($bdem);

$in=[];

for($i=0;$i<$count;$i++){

similar_text($content,$bdem[$i]['content'],$per);

$ii=ceil($per);

$similar[]=$ii;

if($ii>90){

$in[]=[

'similar'=>$ii,

"content"=>$bdem[$i]['content'],

'url'=>$bdem[$i]['url']

];

}

}

array_multisort(array_column($in,'similar'),SORT_DESC,$in);

if(isset($in['0'])){

$in=$in['0'];

};

return [

'similar'=>(100-array_sum($similar)/count($bdem)),

'content'=>$in,

];



}

}



function mbStrSplit ($string, $len=38) {

  $start = 0;

  $strlen = mb_strlen($string);

  while ($strlen) {

    $array[] = mb_substr($string,$start,$len,"utf8");

    $string = mb_substr($string, $len, $strlen,"utf8");

    $strlen = mb_strlen($string);

  }

  return $array;

}



function ycl($content){

$info=mbStrSplit($content);

$count=count($info)-1;

if($count<11){

$rand=$count+1;

}else{

$rand='10';

}

$tmp = range(0,$count);

$array_rand=array_rand($tmp,$rand);


foreach($array_rand as $v){

$ycl[]=bdycl($info[$v]);


}

$count=count($ycl);

for($i=0;$i<$count;$i++){

$similar[$i]=$ycl[$i]['similar'];

//

if(isset($ycl[$i]['content']['similar'])){

$con[$i]=$ycl[$i]['content'];

}


}

$ycd=ceil(((array_sum($similar)/count($ycl))));


if($ycd <=30){

$str = "原创度非常低,不建议发布。";

}else if($ycd <=60 && $ycd > 30){

$str = "原创度比较低,建议修改后再发布。";

}else if($ycd <=75 && $ycd > 60){

$str = "原创度还可以,建议修改后再发布。";

}else if($ycd <= 85 && $ycd > 75){

$str = "原创度较好,属于原创文章,可以发布。";

}else if($ycd > 85){

$str = "原创度非常棒,属于原创文章,可以发布。";

}

$content=array_values($con);

if(!$content){

$content=array();

}

return ['ycl'=>$ycd,'info'=>$str,'content'=>$content]; 

}


function ClearHtml($str) 

    $str = trim($str);

    $str = strip_tags($str,"");

    $str = preg_replace("/\t/","",$str);

    $str = preg_replace("/\r\n/","",$str); 

    $str = preg_replace("/\r/","",$str); 

    $str = preg_replace("/\n/","",$str); 

    $str = preg_replace("/ /","",$str);

    $str = preg_replace("/  /","",$str);

    return trim($str); 

}





感谢大佬提供如此优秀的程序,有BUG联系站长修复!

推否,岂止于SEO

  • 上一篇:
  • 下一篇: 暂无资料
  • 更新文章