PHP 使用 Phantomjs 需开启 proc_open, 本文中使用 PHP 7, ThinkPHP 5, Phantomjs 2.1.1
从错误代码中可以看到是 proc_open 被禁用了。 Continue reading Error when executing PhantomJs procedure – proc_open() has been disabled for security reasons 错误解决
学习日志 LIUGUOFENG
PHP 使用 Phantomjs 需开启 proc_open, 本文中使用 PHP 7, ThinkPHP 5, Phantomjs 2.1.1
从错误代码中可以看到是 proc_open 被禁用了。 Continue reading Error when executing PhantomJs procedure – proc_open() has been disabled for security reasons 错误解决
location ~ .+\.php($|/) {
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^((?U).+.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name;
include fastcgi_params;
}
ThinkPHP 5 部署在了LAMP/LNMP 环境上很有可能出现 Error 500 的情况,这个时候需要开启 php 错误提示来判断是否是因为设置了open_basedir 选项出错。 Continue reading ThinkPHP 5 LNMP PHP 7 环境 服务器 Error 500 错误
$str=preg_replace("/\s+/", " ", $str); //过滤多余回车
$str=preg_replace("/<[ ]+/si","<",$str); //过滤<__("<"号后面带空格)
$str=preg_replace("/<\!--.*?-->/si","",$str); //注释
$str=preg_replace("/<(\!.*?)>/si","",$str); //过滤DOCTYPE
$str=preg_replace("/<(\/?html.*?)>/si","",$str); //过滤html标签
$str=preg_replace("/<(\/?head.*?)>/si","",$str); //过滤head标签
$str=preg_replace("/<(\/?meta.*?)>/si","",$str); //过滤meta标签
$str=preg_replace("/<(\/?body.*?)>/si","",$str); //过滤body标签
$str=preg_replace("/<(\/?link.*?)>/si","",$str); //过滤link标签
$str=preg_replace("/<(\/?form.*?)>/si","",$str); //过滤form标签
$str=preg_replace("/cookie/si","COOKIE",$str); //过滤COOKIE标签
$str=preg_replace("/<(applet.*?)>(.*?)<(\/applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(\/?applet.*?)>/si","",$str); //过滤applet标签
$str=preg_replace("/<(style.*?)>(.*?)<(\/style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(\/?style.*?)>/si","",$str); //过滤style标签
$str=preg_replace("/<(title.*?)>(.*?)<(\/title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(\/?title.*?)>/si","",$str); //过滤title标签
$str=preg_replace("/<(object.*?)>(.*?)<(\/object.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(\/?objec.*?)>/si","",$str); //过滤object标签
$str=preg_replace("/<(noframes.*?)>(.*?)<(\/noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(\/?noframes.*?)>/si","",$str); //过滤noframes标签
$str=preg_replace("/<(i?frame.*?)>(.*?)<(\/i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(\/?i?frame.*?)>/si","",$str); //过滤frame标签
$str=preg_replace("/<(script.*?)>(.*?)<(\/script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/<(\/?script.*?)>/si","",$str); //过滤script标签
$str=preg_replace("/javascript/si","Javascript",$str); //过滤script标签
$str=preg_replace("/vbscript/si","Vbscript",$str); //过滤script标签
$str=preg_replace("/on([a-z]+)\s*=/si","On\=",$str); //过滤script标签
$str=preg_replace("/&#/si","&#",$str); //过滤script标签,如javAsCript:alert(
QueryList 3.0 指导文档
PHP 使用 QueryList 轻松采集 JavaScript 动态渲染页面
做个记录
symfony/dom-crawler 使用入门
> composer require "symfony/dom-crawler"
<?php
use Symfony\Component\DomCrawler\Crawler;
require 'vendor/autoload.php';
$html = <<<'HTML'
<!DOCTYPE html>
<html>
<body>
<p class="message">Hello World!</p>
<p>Hello Crawler!</p>
</body>
</html>
HTML;
$crawler = new Crawler($html);
foreach ($crawler as $domElement) {
var_dump($domElement->nodeName);
}
http://symfony.com/doc/current/components/dom_crawler.html
https://segmentfault.com/q/1010000009019518
PHP 使用 CURL 进行输出时乱码,因为有些网页编码为 GBK 或 GB2312,需要把GBK,GB2312等网页常用格式转成UTF-8。
if(! mb_check_encoding($str, 'utf-8')) {
$str = mb_convert_encoding($str,'UTF-8','gbk');
}
<?php
function str_rev($str){
for($i = 0;true;$i++){
if(!isset($str[$i])){
break;
}
}
$return = "";
for($j=$i-1;$j>=0;$j--){
$return .= $str[$j];
}
return $return;
}
echo str_rev('abcdefg');
输出:
gfedcba
重点:字符串可以当数组来使用。
字符串中的字符可以通过一个以0为开始的,用类似数组结构中的方括号包含对应的数字来查找和修改,比如 $str[42], 可以把 字符串想像数组 。
跳出循环,使用 isset() 来判断。
<?php
function array_mer(){
$return = [];
$array = func_get_args();
foreach($array as $arr){
if(is_array($arr)){
foreach($arr as $val){
$return[] = $val;
}
}
}
return $return;
}
var_dump(array_mer([1],[1,2],[3,5]));
输出:
array(5) {
[0]=>
int(1)
[1]=>
int(1)
[2]=>
int(2)
[3]=>
int(3)
[4]=>
int(5)
}
重点:func_get_args() 动态获取参数的函数