开发者

preg_replace taking out an extra string

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\/([^\/]+)\//
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜