Jump to content

Recommended Posts

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:

th_37209_linebreaks_122_471lo.gif

 

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. 

Link to comment
https://forums.phpfreaks.com/topic/50708-line-breaks-impossible-to-convert/
Share on other sites

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

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.

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...

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

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.