如何在 php 中使用 preg_replace() 排除一段字符串

how to exclude a piece of string using preg_replace() in php

我在 php

中有这个由 wordpress 函数生成的字符串

D:\wamp\www\myProject/wp-content/uploads/2015/11

我想删除

的部分

D:\wamp\www\myProject/

并且只有使用 preg_replace()

的结果

uploads/2015/11

我知道这是一个愚蠢的问题,但我是 wordpress 的新手,并且有点 php。

干杯!

您可以为此使用 str_replace()

$input = "D:\wamp\www\myProject/wp-content/uploads/2015/11";
$output = str_replace("D:\wamp\www\myProject/", "", $input);

str_replace(); 语法:http://php.net/manual/en/function.str-replace.php

使用这个正则表达式:

$path = "D:\wamp\www\myProject/wp-content/uploads/2015/11";
$the_desired_part = preg_replace("/.+?\/(wp-content.+?)/", "", $path);
echo $the_desired_part;