```
public static function getResourceByTemp($html)
{
$attr = ['title', 'alt', 'placeholder'];//指定html屬性上的文本
$getAttrArr = [];
foreach ($attr as $k => $v) {
preg_match_all("/{$v}=\"(.*?)\"/", $html, $get);
if (!empty($get['1'])) {
$getAttrArr = array_unique(array_merge($getAttrArr, $get['1']));
}
}
$html = preg_replace("/<!--.*?-->/is", '', $html); //刪除注釋
$html = preg_replace("/<style.*?>.*?<\/style>/is", '', $html); //刪除style標簽
$html = preg_replace("/<script.*?>.*?<\/script>/is", '', $html); //刪除js標簽
$separator = '::#::myself::#::'; //自己設定的,特有的分隔符
$html = preg_replace("/<.*?>/is", $separator, $html);
$arr = array_filter(explode($separator, $html));
if (!empty($getAttrArr)) {
$arr = array_filter(array_unique(array_merge($arr, $getAttrArr)));
}
$array = [];
foreach ($arr as $k => $v) {
$v = trim($v);
if (!empty($v)) {
if (strpos(PHP_EOL, $v)) {
//有些字符里面會還有換行,再分析一次并去掉字符前后的空格。
$tmp = explode(PHP_EOL, $v);
foreach ($tmp as $val) {
$val = trim($val);
if (!empty($val)) {
$array[] = $val;
}
}
} else {
//如果沒有換行,直接賦值
$array[] = $v;
}
}
}
foreach ($array as $k => $v) {
//去掉純數字的元素
if (is_numeric($v)) {
unset($array[$k]);
}
//去掉純符號的元素
$pregStr = preg_replace("/[\x{4e00}-\x{9fa5}A-Za-z0-9]/u", '', $v);
if ($v == $pregStr) {
unset($array[$k]);
}
//去掉類似這種圖標字符
if (strpos($v, '&#x') !== false && (strlen($v) == 7 || strlen($v) == 8)) {
unset($array[$k]);
}
}
$result = [];
$array = array_unique($array);
foreach ($array as $v) {
$result[] = ['text' => trim($v), 'len' => mb_strlen($v)];
}
array_multisort(array_column($result, 'len'), SORT_DESC, $result); //按字符長度倒序
return $result;
}
```
```
//獲取頁面的title,keyword,description
public static function get_sitemeta($data)
{
if (self::isUrl($data)) {
$data = file_get_contents($url);
}
$meta = array();
if (!empty($data)) {
#Title
preg_match('/<TITLE>([\w\W]*?)<\/TITLE>/si', $data, $matches);
if (!empty($matches[1])) {
$meta['title'] = $matches[1];
}
#Keywords
preg_match('/<META\s+name="keywords"\s+content="([\w\W]*?)"/si', $data, $matches);
if (empty($matches[1])) {
preg_match("/<META\s+name='keywords'\s+content='([\w\W]*?)'/si", $data, $matches);
}
if (empty($matches[1])) {
preg_match('/<META\s+content="([\w\W]*?)"\s+name="keywords"/si', $data, $matches);
}
if (empty($matches[1])) {
preg_match('/<META\s+http-equiv="keywords"\s+content="([\w\W]*?)"/si', $data, $matches);
}
if (!empty($matches[1])) {
$meta['keywords'] = $matches[1];
}
#Description
preg_match('/<META\s+name="description"\s+content="([\w\W]*?)"/si', $data, $matches);
if (empty($matches[1])) {
preg_match("/<META\s+name='description'\s+content='([\w\W]*?)'/si", $data, $matches);
}
if (empty($matches[1])) {
preg_match('/<META\s+content="([\w\W]*?)"\s+name="description"/si', $data, $matches);
}
if (empty($matches[1])) {
preg_match('/<META\s+http-equiv="description"\s+content="([\w\W]*?)"/si', $data, $matches);
}
if (!empty($matches[1])) {
$meta['description'] = $matches[1];
}
}
return $meta;
}
```
- 技能知識點
- 對死鎖問題的理解
- 文件系統原理:如何用1分鐘遍歷一個100TB的文件?
- 數據庫原理:為什么PrepareStatement性能更好更安全?
- Java Web程序的運行時環境到底是怎樣的?
- 你真的知道自己要解決的問題是什么嗎?
- 如何解決問題
- 經驗分享
- GIT的HTTP方式免密pull、push
- 使用xhprof對php7程序進行性能分析
- 微信掃碼登錄和使用公眾號方式進行掃碼登錄
- 關于curl跳轉抓取
- Linux 下配置 Git 操作免登錄 ssh 公鑰
- Linux Memcached 安裝
- php7安裝3.4版本的phalcon擴展
- centos7下php7.0.x安裝phalcon框架
- 將字符串按照指定長度分割
- 搜索html源碼中標簽包的純文本
- 更換composer鏡像源為阿里云
- mac 隱藏文件顯示/隱藏
- 谷歌(google)世界各國網址大全
- 實戰文檔
- PHP7安裝intl擴展和linux安裝icu
- linux編譯安裝時常見錯誤解決辦法
- linux刪除文件后不釋放磁盤空間解決方法
- PHP開啟異步多線程執行腳本
- file_exists(): open_basedir restriction in effect. File完美解決方案
- PHP 7.1 安裝 ssh2 擴展,用于PHP進行ssh連接
- php命令行加載的php.ini
- linux文件實時同步
- linux下php的psr.so擴展源碼安裝
- php將字符串中的\n變成真正的換行符?
- PHP7 下安裝 memcache 和 memcached 擴展
- PHP 高級面試題 - 如果沒有 mb 系列函數,如何切割多字節字符串
- PHP設置腳本最大執行時間的三種方法
- 升級Php 7.4帶來的兩個大坑
- 不同域名的iframe下,fckeditor在chrome下的SecurityError,解決辦法~~
- Linux find+rm -rf 執行組合刪除
- 從零搭建Prometheus監控報警系統
- Bug之group_concat默認長度限制
- PHP生成的XML顯示無效的Char值27消息(PHP generated XML shows invalid Char value 27 message)
- XML 解析中,如何排除控制字符
- PHP各種時間獲取
- nginx配置移動自適應跳轉
- 已安裝nginx動態添加模塊
- auto_prepend_file與auto_append_file使用方法
- 利用nginx實現web頁面插入統計代碼
- Nginx中的rewrite指令(break,last,redirect,permanent)
- nginx 中 index try_files location 這三個配置項的作用
- linux安裝git服務器
- PHP 中運用 elasticsearch
- PHP解析Mysql Binlog
- 好用的PHP學習網(持續更新中)
- 一篇寫給準備升級PHP7的小伙伴的文章
- linux 安裝php7 -系統centos7
- Linux 下多php 版本共存安裝
- PHP編譯安裝時常見錯誤解決辦法,php編譯常見錯誤
- nginx upstream模塊--負載均衡
- 如何解決Tomcat服務器打開不了HOST Manager的問題
- PHP的內存泄露問題與垃圾回收
- Redis數據結構 - string字符串
- PHP開發api接口安全驗證
- 服務接口API限流 Rate Limit
- php內核分析---內存管理(一)
- PHP內存泄漏問題解析
- 【代碼片-1】 MongoDB與PHP -- 高級查詢
- 【代碼片-1】 php7 mongoDB 簡單封裝
- php與mysql系統中出現大量數據庫sleep的空連接問題分析
- 解決crond引發大量sendmail、postdrop進程問題
- PHP操作MongoDB GridFS 存儲文件,如圖片文件
- 淺談php安全
- linux上keepalived+nginx實現高可用web負載均衡
- 整理php防注入和XSS攻擊通用過濾