1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php正则表达式提取url php 正则表达式提取图片url程序

php正则表达式提取url php 正则表达式提取图片url程序

时间:2022-08-28 06:33:55

相关推荐

php正则表达式提取url php 正则表达式提取图片url程序

先用正则表达式获取IMG标签,然后把每个IMG标签的SRC抽取出来,并且组合成自己的内容,最后进行替换

我想对 html 的图片进行提取.

如上地址. 我想全部提取出来 但是包含'ico' 的地址 忽略. 求正则 , 就是有些图片 提取.有些不提取.

例子:]*?srcs*=s*('|")(.*?)\1[^>]*?/?s*>

经改进后..

正确解答如下//

实例//要替换的内容

$content = '';

//提取图片路径的src的正则表达式

preg_match_all("/]+>/isU",$content,$matches);

$img = "";

if(!empty($matches)) {

//注意,上面的正则表达式说明src的值是放在数组的第三个中

$img = $matches[2];

}else {

$img = "";

}

if (!empty($img)) {

$img_url = "http://".$_SERVER['SERVER_NAME'];

$patterns= array();

$replacements = array();

foreach($img as $imgItem){

$final_imgUrl = $img_url.$imgItem;

$replacements[] = $final_imgUrl;

$img_new = "/".preg_replace("///i","/",$imgItem)."/";

$patterns[] = $img_new;

}

//让数组按照key来排序

ksort($patterns);

ksort($replacements);

//替换内容

$vote_content = preg_replace($patterns, $replacements, $content);

相关文章:

发布php中文网,转载请注明出处,感谢您的尊重!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。