Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
从字符串的开头和结尾删除所有非字母数字字符的最佳方法是什么?
~~STRING~~ => STRING "STRING" => STRING **STRING** => STRING **STR**ING** => STR**ING
您可以使用:
$repl = preg_replace('#^\W+|\W+$#', '', $str)
trim($string, $charlist)应该做的伎俩。
trim($string, $charlist)
$str = preg_replace('/^\W*(.*\w)\W*$/', '$1', $str);