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

Q

How To Remove the New Line Character from the End of a Text Line? - PHP Script Tips - PHP Built-in Functions for Strings

✍: FYIcenter.com

A

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:

<?php
$handle = fopen("/tmp/inputfile.txt", "r");
while ($line=fgets()) {
  $line = chop($line);
  # process $line here...
}
fclose($handle);
?> 

2007-04-22, 4814👍, 0💬