Basic PHP Programming Question:

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

PHP Interview Question
PHP Interview Question

Answer:

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);
?>



Previous QuestionNext Question
How To Remove White Spaces from the Beginning and/or the End of a String in PHP?How To Remove Leading and Trailing Spaces from User Input Values in PHP?