1、获取所有链接内容和地址

function getAllURL($code){
  preg_match_all('/<as+href=["|']?([^>"']+)["|']?s*[^>]*>([^>]+)</a>/i',$code,$arr);
  return array('name'=>$arr[2],'url'=>$arr[1]);
}

2、获取所有的图片地址

function getImgSrc($code){
  $reg="/]*src="(http://(.+)/(.+).(jpg|gif|bmp|bnp|png))"/isU";
  preg_match_all($reg,$code,$img_array,PREG_PATTERN_ORDER);
  return $img_array[1];
}

3、当前的脚本网址

function getSelfURL(){
if(!empty($_SERVER["REQUEST_URI"])){
$scriptName = $_SERVER["REQUEST_URI"];
$nowurl = $scriptName;
}else{
$scriptName = $_SERVER["PHP_SELF"];
if(empty($_SERVER["QUERY_STRING"]))$nowurl=$scriptName;
else$nowurl=$scriptName."?".$_SERVER["QUERY_STRING"];
}
return $nowurl;
}

4、把全角数字转为半角数字

function getAlabNum($fnum){
$nums=array("0","1","2","3","4","5","6","7","8","9");
$fnums = "0123456789";
for($i=0;$i<=9;$i++)$fnum=str_replace($nums[$i],$fnums[$i],$fnum);
$fnum = ereg_replace("[^0-9.]|^0{1,}","",$fnum);
if($fnum=="") $fnum=0;
return $fnum;
}

5、去除HTML标记

function text2Html($txt){
$txt = str_replace(" "," ",$txt);
$txt = str_replace("<","<",$txt);
$txt = str_replace(">",">",$txt);
$txt = preg_replace("/[ ]{1,}/isU","<br/> ",$txt);
return $txt;
}

6、清除HTML标记

function clearHtml($str){
$str = str_replace('<','<',$str);
$str = str_replace('>','>',$str);
return $str;
}

7、相对路径转化成绝对路径

function relative2Absolute($content, $feed_url) {
preg_match('/(http|https|ftp):///',$feed_url, $protocol);
$server_url = preg_replace("/(http|https|ftp|news):///", "", $feed_url);
$server_url = preg_replace("//.*/", "", $server_url);
if ($server_url == '') {
return $content;
}
if (isset($protocol[0])) {
$new_content=preg_replace('/href="//', 'href="'.$protocol[0].$server_url.'/', $content);
$new_content=preg_replace('/src="//', 'src="'.$protocol[0].$server_url.'/', $new_content);
} else {
$new_content = $content;
}
return $new_content;
}

8、获取指定标记中的内容

function getTagData($str, $start, $end){
if ( $start == '' || $end == '' ){
return;
}
$str = explode($start, $str);
$str = explode($end, $str[1]);
return $str[0];
}

9、HTML表格的每行转为CSV格式数组

function getTrArray($table) {
$table = preg_replace("'<td[^>]*?>'si",'"',$table);
$table = str_replace("</td>",'",',$table);
$table = str_replace("</tr>","{tr}",$table);
//去掉 HTML 标记
$table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);
//去掉空白字符
$table = preg_replace("'([ ])[s]+'","",$table);
$table = str_replace(" ","",$table);
$table = str_replace(" ","",$table);
$table = explode(",{tr}",$table);
array_pop($table);
return $table;
}

10、将HTML表格的每行每列转为数组,采集表格数据

function getTdArray($table) {
$table = preg_replace("'<table[^>]*?>'si","",$table);
$table = preg_replace("'<tr[^>]*?>'si","",$table);
$table = preg_replace("'<td[^>]*?>'si","",$table);
$table = str_replace("</tr>","{tr}",$table);
$table = str_replace("</td>","{td}",$table);
//去掉 HTML 标记
$table = preg_replace("'<[/!]*?[^<>]*?>'si","",$table);
//去掉空白字符
$table = preg_replace("'([ ])[s]+'","",$table);
$table = str_replace(" ","",$table);
$table = str_replace(" ","",$table);
$table = explode('{tr}', $table);
array_pop($table);
foreach ($table as $key=>$tr) {
$td = explode('{td}', $tr);
array_pop($td);
$td_array[] = $td;
}
return $td_array;
}

11、返回字符串中的所有单词 $distinct=true 去除重复

function splitEnStr($str,$distinct=true) {
preg_match_all('/([a-zA-Z]+)/',$str,$match);
if ($distinct == true) {
$match[1] = array_unique($match[1]);
}
sort($match[1]);
return $match[1];
}

PHP常用采集函数总结的更多相关文章

  1. oracle(sql)基础篇系列(一)——基础select语句、常用sql函数、组函数、分组函数

        花点时间整理下sql基础,温故而知新.文章的demo来自oracle自带的dept,emp,salgrade三张表.解锁scott用户,使用scott用户登录就可以看到自带的表. #使用ora ...

  2. php常用字符串函数小结

    php内置了98个字符串函数(除了基于正则表达式的函数,正则表达式在此不在讨论范围),能够处理字符串中能遇到的每一个方面内容,本文对常用字符串函数进行简单的小结,主要包含以下8部分:1.确定字符串长度 ...

  3. php常用数组函数回顾一

    数组对于程序开发来说是一个必不可少的工具,我根据网上的常用数组函数,结合个人的使用情况,进行数组系列的总结复习.里面当然不只是数组的基本用法,还有相似函数的不同用法的简单实例,力求用最简单的实例,记住 ...

  4. byte数据的常用操作函数[转发]

    /// <summary> /// 本类提供了对byte数据的常用操作函数 /// </summary> public class ByteUtil { ','A','B',' ...

  5. WordPress主题模板层次和常用模板函数

    首页: home.php index.php 文章页: single-{post_type}.php – 如果文章类型是videos(即视频),WordPress就会去查找single-videos. ...

  6. Python 常用string函数

    Python 常用string函数 字符串中字符大小写的变换 1. str.lower()   //小写>>> 'SkatE'.lower()'skate' 2. str.upper ...

  7. MySQL之MySQL常用的函数方法

    MySQL常用函数 本篇主要总结了一些在使用MySQL数据库中常用的函数,本篇大部分都是以实例作为讲解,如果有什么建议或者意见欢迎前来打扰. limit Select * from table ord ...

  8. Delphi常用系统函数总结

    Delphi常用系统函数总结 字符串处理函数 Unit System 函数原型 function Concat(s1 [, s2,..., sn]: string): string; 说明 与 S : ...

  9. iOS开发数据库篇—SQLite常用的函数

    iOS开发数据库篇—SQLite常用的函数 一.简单说明 1.打开数据库 int sqlite3_open( const char *filename,   // 数据库的文件路径 sqlite3 * ...

随机推荐

  1. [BZOJ3990]:[SDOI2015]排序(搜索)

    题目传送门 题目描述 小A有一个1-${2}^{N}$的排列A[1..${2}^{N}$],他希望将A数组从小到大排序,小A可以执行的操作有N种,每种操作最多可以执行一次,对于所有的i(1≤i≤N), ...

  2. linux文件重定向

    1:标准输出:2:错误输出 1,exec启动一个新的shell将STDOUT文件描述符重定向到文件 #!/bin/shecho "test exec..."exec > ou ...

  3. 使用http-server在本地搭建一个HTTP服务器

    安装http-server 在控制台中输入 npm install http-server -g 进行全局安装 共享资源 进入需要共享资源的目录,比如 D:\,然后在控制台中输入 http-serve ...

  4. 【机器学习速成宝典】模型篇06决策树【ID3、C4.5、CART】(Python版)

    目录 什么是决策树(Decision Tree) 特征选择 使用ID3算法生成决策树 使用C4.5算法生成决策树 使用CART算法生成决策树 预剪枝和后剪枝 应用:遇到连续与缺失值怎么办? 多变量决策 ...

  5. ActiveMQ从入门到精通(一)

    这是关于消息中间件ActiveMQ的一个系列专题文章,将涵盖JMS.ActiveMQ的初步入门及API详细使用.两种经典的消息模式(PTP and Pub/Sub).与Spring整合.ActiveM ...

  6. nodejs 中 接受前端的数据请求的处理

    前台 ---->  后台 后台要接受 前台的数据,只能通过 http 但是 前台接受 后台的数据有  from   ajax    jsonp nodejs 给我们提供了模块 url 模块,可以 ...

  7. leetcode-mid-design-380. Insert Delete GetRandom O(1)

    mycode import random class RandomizedSet(object): def __init__(self): """ Initialize ...

  8. C语言:结构体中(.)和(->)的区别

    https://blog.csdn.net/faihung/article/details/79190039 这虽然是个小问题,但有时候很容易让人迷惑,因为有的时候用混淆了,程序编译不通过. 下面说说 ...

  9. Monkey测试:启动adb shell失败

    1.在dos环境下输入adb shell 2.遇到adb server version doesn't match this client:killing错误 如: 3.在遇到如上问题时,输入adb ...

  10. vue--综合组件间的通信

    二.综合组件之间的通信 实现一个ToDoList. ①完成所有的组件的创建和使用 ②add点击add按钮时候,将用户输入的内容(todoinput),显示在(todolist) 核心代码:兄弟组件间通 ...