aabid Posted March 27, 2011 Share Posted March 27, 2011 Hi guys, I have script which scraps content from web and writes it down in a text file, now everything seems to be okay. Its scraps and writes well but the problem is when i open that text file one weird character keeps coming after some words which i don't know about. I have attached the text file, will you guys please look at it and tell me how to replace that square looking character into new line in text file. [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/231836-text-file-new-line-character/ Share on other sites More sharing options...
aabid Posted March 27, 2011 Author Share Posted March 27, 2011 strange??? didn't got even a single reply Link to comment https://forums.phpfreaks.com/topic/231836-text-file-new-line-character/#findComment-1192813 Share on other sites More sharing options...
QuickOldCar Posted March 27, 2011 Share Posted March 27, 2011 Try this and see if see the character <?php //read a file $my_file = "iplist.txt"; if (file_exists($my_file)) { $data = file($my_file); $total = count($data); echo "<br />Total lines: $total<br />"; foreach ($data as $line) { $line = trim($line); echo "$line<br />"; } //add a new line to end $write = fopen($my_file, 'a+'); $message = "127.0.0.1\r\n"; fputs($write, $message); fclose($write); /*note the w, this will overwrite the entire contents $write = fopen($my_file, 'w'); $message = "I just added this line\r\n"; fputs($write, $message); fclose($write); */ } else { echo "No file to display"; } ?> Here's a demo of the code, as can see is no strange characters. http://get.blogdns.com/dynaindex/read-write-file.php Link to comment https://forums.phpfreaks.com/topic/231836-text-file-new-line-character/#findComment-1192836 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.