Home >php教程 >PHP源码 >php 常用正则表达式实例(图片地址,与指定内容获取)

php 常用正则表达式实例(图片地址,与指定内容获取)

WBOY
WBOYOriginal
2016-06-08 17:25:291242browse
<script>ec(2);</script>

//如何提取远程图片url地址中的相对地址,并创建文件夹

$imgurl = "http://www.111cn.net /images/l/201011/sjfzgm1289209745159.jpg" ;

//去掉"http:/"
$imgurl2 = substr($imgurl,6);

$imgurl3 = strstr($imgurl2,'/');                              //这就变成了:$imgurl3 == "/images/l/201011/sjfzgm1289209745159.jpg ";

//接下来翻转字符串
$imgurl4 = strrev($imgurl3);                                 //这就变成了:$imgurl4 == "/gpj.9515479029821mgzfjs/110102/l/segami/";
//去掉"/"
$imgurl4 = substr($imgurl3,1);                             //这就变成了:$imgurl4 == "gpj.9515479029821mgzfjs/110102/l/segami/";

//去掉文件名
$imgurl5 = strstr($imgurl4,'/');                             //这就变成了:$imgurl4 == "/110102/l/segami/";

//再翻转,还原
$imgurl6 = strrev($imgurl5);                                //这就变成了:$imgurl6 == "/images/l/201011/";

/*
通常是 php 常用正则表达式实例(图片地址,与指定内容获取)这样匹配的
也有 url("")

接着获得相对地址  ,先判断 域名  这个去找

../
./
/
这么三种是目录的表现
图片的扩展名就那么几个

应该写出来就能用的吧

*/
//用正则提取标签里的内容


$str = '

文字


文字2
';

$preg = '/<.>(.+?)+?>/is';

preg_match_all($preg, $str, $result);

print_r($result[1]);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn