Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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-删除字符串()中的所有内容_Php_String - Fatal编程技术网

PHP-删除字符串()中的所有内容

PHP-删除字符串()中的所有内容,php,string,Php,String,我想删除字符串()中的所有内容。例如,如果我的字符串是$string=“这是一个示例字符串(这是我要删除的部分)” 我用str_replace试过了,但很自然,它只是替换了“(”而不是里面的内容。既然我事先不知道内容,我怎么能这样做呢?这可能行得通 preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $String); 尝试使用此方法。[,,(和)在字符类中没有特殊意义。在这种情况下,它们不需要转义。“可能有用”?那有什么用?我没有得

我想删除字符串()中的所有内容。例如,如果我的字符串是
$string=“这是一个示例字符串(这是我要删除的部分)”

我用str_replace试过了,但很自然,它只是替换了“(”而不是里面的内容。既然我事先不知道内容,我怎么能这样做呢?

这可能行得通

preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $String);

尝试使用此方法。
[
在字符类中没有特殊意义。在这种情况下,它们不需要转义。“可能有用”?那有什么用?我没有得到他想要的东西,所以我给了他我理解的东西。@Mynameisjeff你到底没有理解什么??lool@MysteriousDoorknob你的问题不清楚
$string = "this is an example string (this is the part i want to remove)";
$string2=preg_replace("/\([^)]+\)/","",$string);