I have been trying to upload a .txt to my server via a simple php script I made. Everything seems to uploaded correctly, if I open the .txt in Dreamweaver I can see all the formatting is still in tact with spaces and paragraph breaks.
The problem I have is when I try to open that file with PHP and import the contents onto my site. I’m not using an editor right now, just a simple div where the contents are echoed.
I don’t have much experience with uploading/downloading using PHP. Am I not using a command to handle the file contents and keep the initial formatting?
In the end I want the user to upload a file, and have PHP read the file and extract certain elements from it based on the number of spaces between paragraph breaks and such.
I was able to actually echo the .txt using URLENCODE() which kept the formatting and made all my spaces +’s. Thats the closes I got, but the original file isn’t uploaded in the format so I can’t do a count for +’s and select x characters after the last +.
Hmmm, if someone knows of a script already available that can do this or similar to with me just tweaking that would be awesome.
The upload script is not faulty, you forgot that HTML doesn’t respect whitespace. If you want HTML to respect your whitespace in a piece of text wrap it in the
<pre>tag or through css: