phpmakesmehappy Posted May 9, 2007 Share Posted May 9, 2007 Hi, this is my first time posting a question in ANY forum regarding php, which shows how much I'm pulling my hair here (been coding for years). My problem is this: I need to append a string of data as a new line in a static file. Basically what I'm doing is pulling IP's and adding them to htaccess as "not allowed". I start with a read file as append my master list (that has everything for the htaccess except the last line "allow from all"), append the string of data, then save/close that file. The problem is, everytime it is saved the line breaks are displayed as little "boxes" as demonstrated in this screenshot: This also happens when I simply copy a file that I know is displaying the line breaks correctly, and also if I simply RENAME a working file. All the line breaks get screwed up as those boxes! I know my code is working as I tried it on another PHP5 server running windows professional with apache 2. I've tried everything from string replace in dreamweaver by hitting the "enter" key as the item to replace inside double quotes, to opening the PHP file in notepad and copy/pasting that "box" as the thing to string replace. Incidentally, if I open the notepad file I just did that to in dreamweaver it displays the same way visually as if I hit the enter key (a lot of white space and the string is spread across two lines visually).. I've even tried force encoding the page as UTF-8 but nothing seems to work. All the output displays as a single line of code. It APPEARS to work if I output the file as an html file and view it with my browser, but this is useless as a view-source shows a single line of garbled text still. It appears this is some type of server setup issue and I don't know what to do. I'm running PHP5 with mysql4 on a Plesk 8.0 redhat server. Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/ Share on other sites More sharing options...
effigy Posted May 9, 2007 Share Posted May 9, 2007 Is there an option in your editor for saving in a DOS or Unix format? Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/#findComment-249292 Share on other sites More sharing options...
phpmakesmehappy Posted May 9, 2007 Author Share Posted May 9, 2007 well, even so it's my server that is writing the files with those boxes. I know on my home computer if I don't have a font it will display those boxes for any unrecognized characters. I wonder if this applies to the server not having some font character within the PHP install itself? I can't see that being an issue though as the PHP5 was a version released a couple months ago while the one on my test machine was from a couple years ago Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/#findComment-249299 Share on other sites More sharing options...
per1os Posted May 9, 2007 Share Posted May 9, 2007 The boxes are the line breaks. When my file gets chomped up like that by my server all I simply do is open Wordpad start -> programs -> WordPad Paste the contents in there, they should read all correctly and nicely than copy them and paste them back into the file. Half-assed way to do it but it works. Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/#findComment-249308 Share on other sites More sharing options...
Warptweet Posted May 9, 2007 Share Posted May 9, 2007 For starters, I'm positive that you can use \n for a line break. When displaying your text file images, you can use the following code.. str_replace($text,"\n","</br>",$text); That replaces the \n with </br> to create a line break. Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/#findComment-249316 Share on other sites More sharing options...
phpmakesmehappy Posted May 9, 2007 Author Share Posted May 9, 2007 I've tried the \n stuff to no avail. And this is a file that I'm letting PHP keep track of rather than manually inserting lines into a file. I need it to be real time as well, so even if I did do the copy/paste route it leaves me without real time. I thought about manually doing this, as I've been stuck on this issue for a couple weeks now (devoted about 16 hours or 2 full days trying to figure out why it's not working). This is important enough that I must get a working resolution though... Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/#findComment-249322 Share on other sites More sharing options...
phpmakesmehappy Posted May 9, 2007 Author Share Posted May 9, 2007 Here's something I noted in the PHPINFO() I just ran: auto_detect_line_endings is set to "0" for both local value & master value Figured these had "encoding" in them so I'd paste: iconv.input_encoding Local is: ISO-8859-1 Master is: ISO-8859-1 iconv.internal_encoding Local is: ISO-8859-1 Master is: ISO-8859-1 iconv.output_encoding Local is ISO-8859-1 Master is: ISO-8859-1 mbstring.encoding_translation Off Off mbstring.internal_encoding no value no value Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/#findComment-249328 Share on other sites More sharing options...
phpmakesmehappy Posted May 11, 2007 Author Share Posted May 11, 2007 Anyone? I see this one stumped the pros on this board as well ??? Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/#findComment-250321 Share on other sites More sharing options...
thedarkwinter Posted May 11, 2007 Share Posted May 11, 2007 Hi I skimmed the post not reading to well,so forgive me if im missing bits. On a linux based machine,(or even windows) its probably better to use UTF-8 for a start. Anyway, when opening a text file in windows notepad, i think you are supposed to use "\r\n" for a line break instead of "\n". Probably no help, sorry Cheers, tdw Quote Link to comment https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/#findComment-250388 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.