【请高手给一个php的正则代码去除文本中的空段落,空p标签】教程文章相关的互联网学习教程文章

php文章采集正则代码_php技巧

代码如下://采集html function getwebcontent($url){ $ch = curl_init(); $timeout = 10; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); $contents = trim(curl_exec($ch)); curl_close($ch); return $contents; } //获得标题和url $string = getwebcontent(http://www.***.com/learn/...

PHPsimple_html_dom.php+正则采集文章代码_php技巧

代码如下://包含PHP Simple html Dom 类库文件 include_once('./simplehtmldom/simple_html_dom.php'); //采集html function getwebcontent($url){ $ch = curl_init(); $timeout = 10; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); $contents = trim(curl_exec($ch)); curl_close($ch...

PHPIPV6正则表达式验证代码_php技巧

代码如下:// literally from the ABNF in rfc3986 (thanks to 'WCP') function validateIPv6($IP) { return preg_match('/\A (?: (?: (?:[a-f0-9]{1,4}:){6} ::(?:[a-f0-9]{1,4}:){5} (?:[a-f0-9]{1,4})?::(?:[a-f0-9]{1,4}:){4} (?:(?:[a-f0-9]{1,4}:){0,1}[a-f0-9]{1,4})?::(?:[a-f0-9]{1,4}:){3} (?:(?:[a-f0-9]{1,4}:){0,2}[a-f0-9]{1,4})?::(?:[a-f0-9]{1,4}:){2} (?:(?:[a-f0-9]{1,4}:){0,3}[a-f0-9]{1,4})?::[a-f0-9]{1,4}:...

php下正则来匹配dede模板标签的代码_php技巧

html代码 代码如下: {t:arc row=10} {t:field.title/} {t:list row=5} {t:field.title/} {t:list row=5} {t:field.title/} {/t:list}{t:field.title/} {/t:list}{t:field.title/} {/t:arc} {T:channelartlist row=6 } {t:field name=typename/}{t:field.typename/} {t:arclist titlelen=42 row=10} [field:title/] ([field:sendtime function="MyDate(m-d,@me)"/]) {/t:arclist} {/t:channelartlist } {t:global.cfg_ti...

php正则过滤html标签、空格、换行符的代码(附说明)_php技巧

代码如下:$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....

php中获取指定IP的物理地址的代码(正则表达式)_php技巧【图】

自己搭建IP数据库占资源,而且更新不便,何不使用现成的IP查询呢?下面自己写了个获取IP物理地址的PHP代码(有一定的瑕疵,请高手不吝赐教) 代码如下: $ipAddr = "218.75.124.100"; $ip138Addr = "http://www.ip138.com/ips8.asp?ip=".$ipAddr."&action=2"; $contents = file_get_contents($ip138Addr); $pattern = "/\/"; $string = $contents; preg_match_all($pattern,$string,$addrArray); $num = count($addrArray...

PHP通过正则表达式下载图片到本地的实现代码_php技巧

代码如下:/* author: ssh_kobe date: 20110602 shortage: 如果网页中的图片路径不是绝对路径,就无法抓取 */ set_time_limit(0);//抓取不受时间限制 $URL='http://pp.baidu.com/';//任意网址 get_pic($URL); function get_pic($pic_url) { //获取图片二进制流 $data=CurlGet($pic_url); /*利用正则表达式得到图片链接*/ $pattern_src = '//'; $num = preg_match_all($pattern_src, $data, $match_src); $arr_src=$match_src[1];//获...

php中通过正则表达式下载内容中的远程图片的函数代码_php技巧

这段程序其实是属于“小偷程序”的重要部分。 这一段程序只是下载远程图片的那一段而已,程序写的比较简单,大多部分都做了注释。 代码如下:if (preg_match_all("/http://[^ "]+[.jpg|.gif|.jpeg|.png]+/ui",stripcslashes($content),$aliurl)){ $i=0; //多个文件++ while(list($key ,$v) = each($aliurl[0])){ //echo $v.""; $filetype = pathinfo($v, PATHINFO_EXTENSION); //获取后缀名 $ff = @file_get_contents($v); //获取2...

php模板函数正则实现代码_php技巧

我看过phpcms、discuz的源码,所以可能就缺乏创新了,不过原理大都相通,只是细节处理可能稍微不同。 说正题,下面开始谈谈具体实现过程了。 1.首先要想好模板文件放在哪?转换后的php文件放哪?还有怎么命名?直接上源码: 代码如下:function template($tpl = index,$dir = hello) { if(!file_exists($pd = TPL_PATH.$dir./))@mkdir($pd,0777) or die("$pd目录创建失败");//如cache/tpl/hello/ if(!file_exists($td = TPL.$dir./...

邮箱正则表达式实现代码(针对php)_php技巧

一直都在网上抄别人写的电话,邮箱正则表达式,今天稍微有点闲情,把一直想自己写个这样的表达式的心愿给完成: 代码如下:/** * 邮箱地址正则表达式 */$preg = '/^(\w{1,25})@(\w{1,16})(\.(\w{1,4})){1,3}$/';$b = 'ffgddayasdadasdf@gmialsdfsdfasd3.com.cn.org';if(preg_match($preg, $b)){ echo "匹配到了";}else{ echo "没有匹配到";}

dedecms采集中可以过滤多行代码的正则表达式

过去用dede采集,总是过滤不掉一行以上的代码,只能一行行的过滤,在网上,发现有很多和我一样的菜鸟。随着不断的使用dede采集,对正则有了更进一步的了解,现在偶用一句正则表达式,同样可以匹配多行代码了。 如:在如下代码中,过滤掉有二行代码的超级链接。 <td align="center"> <a href="http://www.XXX.com/111111.htm">XXX XXX</a> </td> 用下面的过滤,即可实现多行匹配 {dede:trim} <a href="http://www.XXX.com/111111.ht...

PHP simple_html_dom.php+正则 采集文章代码

代码如下:<?php //包含PHP Simple html Dom 类库文件 include_once(./simplehtmldom/simple_html_dom.php); //采集html function getwebcontent($url){ $ch = curl_init(); $timeout = 10; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); $contents = trim(curl_exec($ch)); curl_close...

php 文章采集正则代码

代码如下://采集html function getwebcontent($url){ $ch = curl_init(); $timeout = 10; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1); $contents = trim(curl_exec($ch)); curl_close($ch); return $contents; } //获得标题和url $string = getwebcontent(http://www.***.com/learn/...

PHP IPV6正则表达式验证代码

代码如下:<?php // literally from the ABNF in rfc3986 (thanks to WCP) function validateIPv6($IP) { return preg_match(/\A (?: (?: (?:[a-f0-9]{1,4}:){6} ::(?:[a-f0-9]{1,4}:){5} (?:[a-f0-9]{1,4})?::(?:[a-f0-9]{1,4}:){4} (?:(?:[a-f0-9]{1,4}:){0,1}[a-f0-9]{1,4})?::(?:[a-f0-9]{1,4}:){3} (?:(?:[a-f0-9]{1,4}:){0,2}[a-f0-9]{1,4})?::(?:[a-f0-9]{1,4}:){2} (?:(?:[a-f0-9]{1,4}:){0,3}[a-f0-9]{1,4})?::[a-f0-9]{1,...

php下正则来匹配dede模板标签的代码

html代码 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> {t:arc row=10} {t:field.title/} {t:list row=5} {t:field.title/} {t:list row=5} {t:field.title/} {/t:list}{t...