我让一个preg_replace去掉了不应该移除的字符串的一部分。它应该查找: images_client/39/structure/party-2/并将其替换为: images_client/39/structure/xxx/它确实做到了这一点,但它也删除了apple_logo.jpg之前的图像/部分
<?php
echo '<br>-------- preg_replace on a css string with slashes ------<br>';
$string='/images_client/39/structure/party-2/images/apple_logo.jpg';
echo 'Before: '.$string.'<br>';
print preg_replace("/images_client\/39\/structure\/(\S+)\//", "images_client/39/structure/xxx/", $string) . "\n";
?>发布于 2010-01-24 05:46:28
试试这个:
preg_replace('#images_client/39/structure/[^/]+/#s', 'images_client/39/structure/xxx/');发布于 2010-01-24 05:47:02
尝试[^/]而不是\S
/images_client\/39\/structure\/([^\/]+)\//https://stackoverflow.com/questions/2124857
复制相似问题