Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php preg_替换取出额外的字符串_Php_Preg Replace - Fatal编程技术网

Php preg_替换取出额外的字符串

Php preg_替换取出额外的字符串,php,preg-replace,Php,Preg Replace,我有一个preg_replace,取出了一根不应该移除的绳子的一部分。 它应该寻找:图片\客户/39/结构/第二方/ 并将其替换为:images\u client/39/structure/xxx/ 它确实做到了这一点,但它也删除了苹果logo.jpg之前的图像/部分图像 <?php echo '<br>-------- preg_replace on a css string with slashes ------<br>'; $string=

我有一个preg_replace,取出了一根不应该移除的绳子的一部分。 它应该寻找:图片\客户/39/结构/第二方/ 并将其替换为:images\u client/39/structure/xxx/ 它确实做到了这一点,但它也删除了苹果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";
?>
试试这个:

preg_replace('#images_client/39/structure/[^/]+/#s', 'images_client/39/structure/xxx/');
请尝试[^/]而不是\S:


请在处理包含正斜杠的图案时,选择一个不同的图案分隔符,您可以选择任何您想要的:所有这些\/使眼睛流血。你也可以考虑接受一些答案。
/images_client\/39\/structure\/([^\/]+)\//