使用正则表达式 ^\$_POST\[[^]]+\]$str = '$_POST["a_string_of_unspecified_length"][4]input&set1';preg_match('~^\$_POST\[[^]]+\]~', $str, $matches);print_R($matches);// $_POST["a_string_of_unspecified_length"]^ - beginning of string\$ - escaped dollar sign_POST - normal characters, just part of string\[ - escaped '['[^]]+ - everything till ']', + means 'more than 1 character'\] - escaped '['the rest doesn't care us, there can be whatever如果需要,没有正则表达式$str = '$_POST["a_string_of_unspecified_length"][4]input&set1';echo substr($str, 0, strpos($str, ']') + 1);// $_POST["a_string_of_unspecified_length"]