[英]How to remove the probable dot at the beginning/end of string in PHP?
我尝试了这个:
echo preg_replace('/[^,,$]/', '', ',test,hi,');
但得到:
,,,
你的意思是
preg_replace('/^,|,$/', '', ',test,hi,');
? 在字符类[…]
,前导^
表示取反,而$
没有任何特殊含义。
您可以改用trim
功能 。
trim(',test,hi,', ',');
preg_replace有点矫kill过正
$string = ',,ABCD,EFG,,,,';
$newString trim($string,',');
trim(',test,hi,',','); // echoes test,hi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.