Remove Trailing New Line Character in PHP


How To Remove the New Line Character from the End of a Text Line?



If you are using fgets() to read a line from a text file, you may want to use the chop() function to remove the new line character from the end of the line as shown in this PHP script:

$handle = fopen("/tmp/inputfile.txt", "r");
while ($line=fgets()) {
  $line = chop($line);
  # process $line here...


Removing Leading and Trailing Spaces in PHP

Ways to Remove Leading and Trailing White Spaces in PHP

PHP Built-in Functions for Strings

⇑⇑ PHP Tutorials

2016-10-13, 2093🔥, 0💬