当前位置:网站首页>PHP pseudo original API docking method
PHP pseudo original API docking method
2022-07-04 20:04:00 【Yangyang 2013 haha】
Today I want to sum up my php Pseudo original api Docking method , First we know that PHP yes PHP Hypertext preprocessor ( Hypertext and processors ) Abbreviation , The sound of thunder on the day of waking insects , Wake up the hibernating insects . This method is called recursive abbreviation , If opportunity doesn't knock on your door , Then open the door by yourself .
php Pseudo original api Docking source code :
<?php
set_time_limit(270);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
define('TITLE_SEPAR', 'xxx**xxx');
define('TITLE_SEPAR2', '262661');
$url = 'http://api.xiaofamao.com/api.php?json=0&v=1&key= You need to apply for it yourself KEY';
$content_tag_name = ' Content ';
$headdd = '';
$taill = '';
switch($LabelArray['PageType'])
{
case 'List':// Process list page , Can only handle html
break;
case 'Pages':// Process multiple pages , Can only handle html
break;
case 'Content':// Process default pages , Can only handle html
break;
case 'Save':// Tag values can only be processed when saving
// Save the original
try {
/**********************************************************************/
// This step is used to obtain pseudo original articles
/**********************************************************************/
$LabelArray[$content_tag_name] = curl_request($url, array('wenzhang'=>$LabelArray[$content_tag_name]));
$LabelArray[' title '] = get_ai_title2($LabelArray[' title ']);
}
catch (Exception $e) {
$LabelArray[' title '] .= $e->getMessage();
$LabelArray[$content_tag_name] .= $e->getMessage();
}
break;
default:
//$LabelArray[$content_tag_name]=curl_request($url, array('wenzhang'=>$LabelArray[$content_tag_name] ));
}
echo serialize($LabelArray);
function get_ai_title2($title) {
$title = urlencode($title);
$title_ai = curl_request($url);
return $title_ai;
}
function compose_article($title, $content) {
$separator = compose_separator();
return $title.$separator.$content;
}
function compose_separator() {
return PHP_EOL.'('.TITLE_SEPAR2.')'.PHP_EOL;
}
function fix_separator($article) {
return $article;
}
function get_wyc_article($str) {
global $url;
$separator = compose_separator();
$separator = str_replace(PHP_EOL, '', $separator);
$wyc = curl_request($url, array('wenzhang'=>$str));
$wyc_f = $wyc;
$wyc = fix_separator($wyc);
$wyc = explode($separator, $wyc);
if (isset($wyc[0])){
$wyc[0] = str_replace(' title :', '', $wyc[0]);
$wyc[0] = str_replace(' title :', '', $wyc[0]);
$wyc[0] = str_replace(' Objective :', '', $wyc[0]);
$wyc[0] = str_replace(' Objective :', '', $wyc[0]);
$wyc[0] = 'xx`xx'.$wyc[0];
$wyc[0] = str_replace('xx`xx topic ', '', $wyc[0]);
$wyc[0] = str_replace('xx`xx', '', $wyc[0]);
}
//if (isset($wyc[1])) $wyc[1] = trim($wyc[1]);
//$wyc[1] = $wyc_f.'jjjjjjjj'.$wyc[1];
return $wyc;
}
function get_wyc_title($str) {
$title = get_wyc_article($str.PHP_EOL.PHP_EOL.PHP_EOL.$str.PHP_EOL.PHP_EOL.PHP_EOL.$str);
$title = fix_newline($title);
$title = explode(PHP_EOL, $title);
return $title[0];
}
function get_keywords($title, $contents) {
$kws = curl_request($url_kw, array(
'title'=>$title,
'len'=>100,
'text'=>$contents));
return $kws;
}
function remove_alt($contents) {
$contents = preg_replace('/alt=\"(.*)\"/', '', $contents);
return $contents;
}
function fix_title($contents) {
$punctuation_symbol = array('.', '?', ',', ':', ';', '、', '!',
'.', '?', ',', ':', ';', '!');
$contents = str_replace($punctuation_symbol, '', $contents);
return $contents;
}
function br2newline($contents) {
$contents = str_replace('<br>', PHP_EOL, $contents);
$contents = str_replace('<br/>', PHP_EOL, $contents);
$contents = str_replace('<br />', PHP_EOL, $contents);
$contents = str_replace('<BR/>', PHP_EOL, $contents);
$contents = str_replace('<BR>', PHP_EOL, $contents);
$contents = str_replace('<BR />', PHP_EOL, $contents);
return $contents;
}
function newline2br($contnets) {
$contnets = str_replace(PHP_EOL, "<br>", $contnets);
// $contnets = str_replace('><br><', '><', $contnets);
$contnets = str_replace('<p><br>', '<p>', $contnets);
return $contnets;
}
function delete_newline($contents) {
$contents = fix_newline($contents);
// $contents = str_replace(PHP_EOL.PHP_EOL, PHP_EOL, $contents);
// $contents = str_replace('>'.PHP_EOL, '>', $contents);
return $contents;
}
function reset_newline_win($contents) {
// Optimize line breaks
$contents = str_replace("\r\n", "\n", $contents);
$contents = str_replace("\r", "\n", $contents);
$contents = str_replace("\n", PHP_EOL, $contents);
return $contents;
}
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 clean_contents($contents) {
// $str = preg_replace('#<([^>\s/]+)[^>]*>#','<$1>', $contents);
// return $str;
$sa = new cleanHtml;
$sa->allow = array( 'src' );
$sa->exceptions = array(
'img' => array( 'src', 'alt' ),
//'a' => array( 'href', 'title' ),
'iframe'=>array('src','frameborder'),
);
$str = $sa->strip( $contents );
return $str;
}
function xfm_strong_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;
}
}
// Parameters 1: Access to the URL, Parameters 2:post data ( If you don't fill in it, it will be GET), Parameters 3: The submitted $cookies, Parameters 4: Whether to return $cookies
function curl_request($url,$post='',$cookie='', $returnCookie=0){
if (! extension_loaded('curl')) {
file_exists('./ext/php_curl.dll') && dl('php_curl.dll'); // Load extension
}
$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;
}
}
//echo $tag;
// Calculate the length of Chinese string
function utf8_strlen($string = null) {
// Decompose a string into units
preg_match_all("/./us", $string, $match);
// Returns the number of units
return count($match[0]);
}
function reg_escape( $str )
{
$conversions = array( "^" => "\^", "[" => "\[", "." => "\.", "$" => "\$", "{" => "\{", "*" => "\*", "(" => "\(", "\\" => "\\\\", "/" => "\/", "+" => "\+", ")" => "\)", "|" => "\|", "?" => "\?", "<" => "\<", ">" => "\>" );
return strtr( $str, $conversions );
}
/**
* Strip attribute Class
* Remove attributes from XML elements
* @author David (semlabs.co.uk)
* @version 0.2.1
*/
class cleanHtml{
public $str = '';
public $allow = array();
public $exceptions = array();
public $ignore = array();
public function strip( $str )
{
$this->str = $str;
if( is_string( $str ) && strlen( $str ) > 0 )
{
$res = $this->findElements();
if( is_string( $res ) )
return $res;
$nodes = $this->findAttributes( $res );
$this->removeAttributes( $nodes );
}
return $this->str;
}
private function findElements()
{
# Create an array of elements with attributes
$nodes = array();
preg_match_all( "/<([^ !\/\>\n]+)([^>]*)>/i", $this->str, $elements );
foreach( $elements[1] as $el_key => $element )
{
if( $elements[2][$el_key] )
{
$literal = $elements[0][$el_key];
$element_name = $elements[1][$el_key];
$attributes = $elements[2][$el_key];
if( is_array( $this->ignore ) && !in_array( $element_name, $this->ignore ) )
$nodes[] = array( 'literal' => $literal, 'name' => $element_name, 'attributes' => $attributes );
}
}
# Return the XML if there were no attributes to remove
if( !$nodes[0] )
return $this->str;
else
return $nodes;
}
private function findAttributes( $nodes )
{
# Extract attributes
foreach( $nodes as &$node )
{
preg_match_all( "/([^ =]+)\s*=\s*[\"|']{0,1}([^\"']*)[\"|']{0,1}/i", $node['attributes'], $attributes );
if( $attributes[1] )
{
foreach( $attributes[1] as $att_key => $att )
{
$literal = $attributes[0][$att_key];
$attribute_name = $attributes[1][$att_key];
$value = $attributes[2][$att_key];
$atts[] = array( 'literal' => $literal, 'name' => $attribute_name, 'value' => $value );
}
}
else
$node['attributes'] = null;
$node['attributes'] = $atts;
unset( $atts );
}
return $nodes;
}
private function removeAttributes( $nodes )
{
# Remove unwanted attributes
foreach( $nodes as $node )
{
# Check if node has any attributes to be kept
$node_name = $node['name'];
$new_attributes = '';
if( is_array( $node['attributes'] ) )
{
foreach( $node['attributes'] as $attribute )
{
if( ( is_array( $this->allow ) && in_array( $attribute['name'], $this->allow ) ) || $this->isException( $node_name, $attribute['name'], $this->exceptions ) )
$new_attributes = $this->createAttributes( $new_attributes, $attribute['name'], $attribute['value'] );
}
}
$replacement = ( $new_attributes ) ? "<$node_name $new_attributes>" : "<$node_name>";
$this->str = preg_replace( '/'. reg_escape( $node['literal'] ) .'/', $replacement, $this->str );
}
}
private function isException( $element_name, $attribute_name, $exceptions )
{
if( array_key_exists($element_name, $this->exceptions) )
{
if( in_array( $attribute_name, $this->exceptions[$element_name] ) )
return true;
}
return false;
}
private function createAttributes( $new_attributes, $name, $value )
{
if( $new_attributes )
$new_attributes .= " ";
$new_attributes .= "$name=\"$value\"";
return $new_attributes;
}
}
?>
php use ,Php There are many uses estimated brotherhood , Especially for website development , You are ruthless to people , People are mean to you . Fast 、 Flexibility and practicality make php Can better develop any website , Would rather give the gentleman shoes , Refuse to share money with villains .
PHP It's a kind of HTML Embedded scripting language , The summer solstice enters volita , Farming is like watering a garden .Php Document to , It won't rain for a year , People will not be poor for a lifetime .php, Winter is over , pollen , It's hard for everything to recover .c and java The grammatical difference between , Many of its grammars come from C、Java and Perl Or learn well , And have PHP Several unique features of , Gentlemen and villains tend to be different , Between public and private . The main goal of this language is to make Web Developers can quickly write dynamically generated web pages , A gentleman cannot help worrying about his body and mind , It's also necessary to delay the fun of the moon .
php The main application areas of scripts
Server side : Main target areas , If you want to grow well , Fishing for water and grass with mud . This job requires three things :php Parser (CGI Or server module )、web The server and web browser , Think rationally and say , He rushed to say .
linux perform php Script , Command line : Write a php Script or golden moment , Just one php The parser can execute , Greedy ghost is not full , Misers don't know how rich they are .linux start-up crond Timing task , For those who depend on cron(linux) Or task scheduler (windows) For those who run the script, they can either express their opinions , It's an ideal choice , Zhu GUI has a solution , People are willing to ; People are willing to , Learning is expensive and persistent .
php GUI development , Desktop application :php Not good at making graphical interfaces seems perfect , But if the user is proficient php and php Some advanced features of may be better , have access to php-gtk Write desktop applications , The world is black as a crow , The rich in the world are as ruthless .
PHP How to change lines in PHP How to change lines in (PHP Precautions for line breaks ) – Wooden sword advertisement
边栏推荐
- How to use async Awati asynchronous task processing instead of backgroundworker?
- Actual combat simulation │ JWT login authentication
- BCG 使用之CBCGPProgressDlgCtrl进度条使用
- 黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
- Dark horse programmer - software testing - stage 07 2-linux and database -09-24-linux command learning steps, wildcards, absolute paths, relative paths, common commands for files and directories, file
- 1003 emergency (25 points) (PAT class a)
- 1003 Emergency(25 分)(PAT甲级)
- SSRS筛选器的IN运算(即包含于)用法
- Introduction to ACM combination counting
- 如何使用Async-Awati异步任務處理代替BackgroundWorker?
猜你喜欢
Dark horse programmer - software testing - stage 08 2-linux and database-23-30-process port related, modify file permissions, obtain port number information, program and process related operations, Li
Euler function
C语言-入门-基础-语法-流程控制(七)
华为nova 10系列支持应用安全检测功能 筑牢手机安全防火墙
如何使用Async-Awati异步任務處理代替BackgroundWorker?
Dark horse programmer - software testing - 09 stage 2-linux and database -31-43 instructions issued by modifying the file permission letter, - find the link to modify the file, find the file command,
Mysql database basic operation -ddl | dark horse programmer
92. (cesium chapter) cesium building layering
English grammar_ Noun - use
Decryption function calculates "task state and lifecycle management" of asynchronous task capability
随机推荐
BCG 使用之CBCGPTabWnd控件(相当于MFC TabControl)
What are the consequences of closing the read / write channel?
Anhui Zhong'an online culture and tourism channel launched a series of financial media products of "follow the small editor to visit Anhui"
TCP waves twice, have you seen it? What about four handshakes?
An example of multi module collaboration based on NCF
Dark horse programmer - software testing - 09 stage 2-linux and database -31-43 instructions issued by modifying the file permission letter, - find the link to modify the file, find the file command,
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
Niuke Xiaobai month race 7 who is the divine Archer
What should we pay attention to when doing social media marketing? Here is the success secret of shopline sellers!
Cann operator: using iterators to efficiently realize tensor data cutting and blocking processing
HMM hidden Markov model and code implementation
牛客小白月赛7 F题
水晶光电:长安深蓝SL03的AR-HUD产品由公司供应
【毕业季】绿蚁新醅酒,红泥小火炉。晚来天欲雪,能饮一杯无?
1003 emergency (25 points) (PAT class a)
Offset function and windowing function
C # use stopwatch to measure the running time of the program
Stream stream
HDU 1372 & POJ 2243 Knight moves (breadth first search)
Abc229 summary (connected component count of the longest continuous character graph in the interval)