Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does php trim() remove line breaks?

Tags:

php

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 post whitespace)?

like image 506
muncherelli Avatar asked Sep 16 '10 14:09

muncherelli


People also ask

What does PHP trim do?

Definition and Usage. The trim() function removes whitespace and other predefined characters from both sides of a string. Related functions: ltrim() - Removes whitespace or other predefined characters from the left side of a string.

How do you delete a line in PHP?

Remove some extra ones? The common ways to remove line breaks in PHP are: $nobreak = str_replace(["\r", "\n"], "", $STRING); $nobreak = preg_replace("/\r|\n/", "", $STRING);

Does Javascript trim remove newline?

trim method removes any line breaks from the start and end of a string. It handles all line terminator characters (LF, CR, etc). The method also removes any leading or trailing spaces or tabs. The trim() method does not change the original string, it returns a new string.


1 Answers

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.

like image 160
Pekka Avatar answered Oct 17 '22 06:10

Pekka