PHP Developer Question: Download Questions PDF
How you can remove the new line character from the end of a text line in PHP?
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);
?>
<?php
$handle = fopen("/tmp/inputfile.txt", "r");
while ($line=fgets()) {
$line = chop($line);
# process $line here...
}
fclose($handle);
?>
Download PHP Developer Interview Questions And Answers
PDF
Previous Question | Next Question |
How you can remove white spaces from the beginning and/or the end of a String in PHP? | How you can remove leading and trailing spaces from user input values in PHP? |