开发者

Does php trim() remove line breaks?

I am creating an application that takes a "swipe" from a magnetic reader. The string that is returned from the magnetic reader has a line break after the text. Can I use php trim() to remove the linebreak (and obviously any pre or p开发者_如何学JAVAost whitespace)?


Yes it does, see the manual:

This function returns a string with whitespace stripped from the beginning and end of str. Without the second parameter, trim() will strip these characters:

" " (ASCII 32 (0x20)), an ordinary space.
"\t" (ASCII 9 (0x09)), a tab.
"\n" (ASCII 10 (0x0A)), a new line (line feed).
"\r" (ASCII 13 (0x0D)), a carriage return.
"\0" (ASCII 0 (0x00)), the NUL-byte.
"\x0B" (ASCII 11 (0x0B)), a vertical tab.


Also note: trim($string, "\n") or trim($string, " ")


Note that trim will not remove it by default, if it has breakline: <br> at the end, so be careful with that.

Otherwise @Pekka's @Petah's answer is good.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜