I have a preg_replace taking out a part of a string it shouldn't be removing. It should be looking for: images_client/39/structure/party-2/ And replacing it with: images_client/39/structure/xxx/ It does do that, but it's also removing the images/ part of it just before 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_repla开发者_Python百科ce("/images_client\/39\/structure\/(\S+)\//", "images_client/39/structure/xxx/", $string) . "\n";
?>
Try this:
preg_replace('#images_client/39/structure/[^/]+/#s', 'images_client/39/structure/xxx/');
Try [^/]
instead of \S
:
/images_client\/39\/structure\/([^\/]+)\//
精彩评论