开发者

How to remove the probable dot at the beginning/end of string in PHP?

I tried this:

echo preg_replace('/[^,,$]/', '', ',test,hi,');

But gets:

,,,开发者_如何学Python


Do you mean

preg_replace('/^,|,$/', '', ',test,hi,');

? Inside a character class […], a leading ^ means negation, and $ doesn't have any special meanings.

You could use the trim function instead.

trim(',test,hi,', ',');


preg_replace is a bit overkill

$string = ',,ABCD,EFG,,,,';
$newString trim($string,',');


trim(',test,hi,',','); // echoes test,hi
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜