时间:2021-07-01 10:21:17 帮助过:23人阅读
$s =<<< TXTTXT;echo preg_replace('#(?<=src=").*/([^"]+)#', '$1', $s);
$s =<<< TXTTXT;echo preg_replace('#(?<=src=").*/([^"]+)#', '$1', $s);
替换成 类似的应该怎么做,
你的需求不明确,前后矛盾,到底保留文件本身,还是保留文件名以及他的父级目录。
你的需求不明确,前后矛盾,到底保留文件本身,还是保留文件名以及他的父级目录。
$str="src='/n1sss/https://www.gxlcms.com/images'“;
$zz="/src='\/.*\/(.*?)'/";
echo preg_replace($zz,'$1',$str);
$str="src='/n1sss/https://www.gxlcms.com/images'“;
$zz="/src='\/.*\/(.*?)'/";
echo preg_replace($zz,'$1',$str);
TXT;$pattern="/\/.*\/(.*?)\/(.*?)/";echo preg_replace($pattern, '$1/$2', $s);?>
TXT;$pattern="/\/.*\/(.*?)\/(.*?)/";echo preg_replace($pattern, '$1/$2', $s);?>
TXT;$pattern="/\/.*\/(.*?)\/(.*?)/";echo preg_replace($pattern, '$1/$2', $s);?>
$s =<<< TXTTXT;$n = 0; //只留文件名echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);$n = 1; //保留一级目录echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);$n = 2; //保留二级目录echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);
$s =<<< TXTTXT;$n = 0; //只留文件名echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);$n = 1; //保留一级目录echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);$n = 2; //保留二级目录echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);
$s =<<< TXTTXT;$n = 0; //只留文件名echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);$n = 1; //保留一级目录echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);$n = 2; //保留二级目录echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);
$s =<<< TXTTXT;$n = 0; //只留文件名echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);$n = 1; //保留一级目录echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);$n = 2; //保留二级目录echo preg_replace("#(?<=src=['\"]).*/((?:.*/){{$n}}[^'\"]+)#", '$1', $s);
$str="src='/n1sss/https://www.gxlcms.com/images'“;
$zz="/src='\/.*\/(.*?)'/";
echo preg_replace($zz,'$1',$str);