欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

preg_replace怎么将src="/n1/images替换成src="images

程序员文章站 2022-05-05 21:01:50
...
preg_replace怎么将src="/n1/images替换成src="images
src="/n1/images 中的n1 可能是其他字符,比如说m2或者py等。
不懂正则替换,请指点。


回复讨论(解决方案)

$s =preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagesTXT;echo preg_replace('#(?  
preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="images

$s =preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagesTXT;echo preg_replace('#(?   
preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="images


谢谢版主,但如果是 preg_replace怎么将src="/n1/images替换成src="images 怎么办?

preg_replace怎么将src="/n1/images替换成src="images 替换成 preg_replace怎么将src="/n1/images替换成src="images 类似的应该怎么做,

你的需求不明确,前后矛盾,到底保留文件本身,还是保留文件名以及他的父级目录。

你的需求不明确,前后矛盾,到底保留文件本身,还是保留文件名以及他的父级目录。



其实就是将 preg_replace怎么将src="/n1/images替换成src="images 替换成 preg_replace怎么将src="/n1/images替换成src="images
意思是将 images前面的目录删除

$str="src='/n1sss/images'“;

$zz="/src='\/.*\/(.*?)'/";

echo preg_replace($zz,'$1',$str);

$str="src='/n1sss/images'“;

$zz="/src='\/.*\/(.*?)'/";

echo preg_replace($zz,'$1',$str);



这个 $zz="/src='\/.*\/(.*?)'/"; 在PHP里面就有错误

TXT;$pattern="/\/.*\/(.*?)\/(.*?)/";echo preg_replace($pattern, '$1/$2', $s);?>

TXT;$pattern="/\/.*\/(.*?)\/(.*?)/";echo preg_replace($pattern, '$1/$2', $s);?>


谢谢版主的回答,可能我的问题说的不是很明确,
利用preg_replace怎么将images前面的目录删除掉
preg_replace怎么将src="/n1/images替换成src="images 或者preg_replace怎么将src="/n1/images替换成src="images

TXT;$pattern="/\/.*\/(.*?)\/(.*?)/";echo preg_replace($pattern, '$1/$2', $s);?>


还请再帮帮忙

$s =preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagesTXT;$n = 0; //只留文件名echo preg_replace("#(?  
preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="images

$s =preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagesTXT;$n = 0; //只留文件名echo preg_replace("#(?   
preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="images


$s =preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagesTXT;$n = 0; //只留文件名echo preg_replace("#(?   
preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="images


$s =preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagesTXT;$n = 0; //只留文件名echo preg_replace("#(?   
preg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="imagespreg_replace怎么将src="/n1/images替换成src="images


谢谢版主的回答,我有一个文件夹images,我就想保留images文件夹以及后面的目录,images后面的目录有几级是未知的。还请版主帮个忙

$str="src='/n1sss/images'“;

$zz="/src='\/.*\/(.*?)'/";

echo preg_replace($zz,'$1',$str);




我都运行过的没问题,才发出来的啊