开发者

Upload .txt and keep formating

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开发者_JAVA技巧 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.


HTML ignores spacing and newlines.
In order to force the browser to process your whitespace, you need to put the text into a <pre> tag.


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:

white-space: pre;


When you echo text into a div I bet you that the formatting is actually being kept, but HTML tends to make a sequence of whitespaces into a single whitespace when it displays on the web page. Try "View Source" and I bet your formatting is still there. In order to show the formatting properly try echoing the text content into a "pre" tag instead of a div

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜