lional Posted October 3, 2008 Share Posted October 3, 2008 Hi Is is possible to read in a file such as a word document with readfile and to keep the file formatting such as new lines, paragraphs, bold face etc? ThaNKS Lional Link to comment https://forums.phpfreaks.com/topic/126855-file-formatting/ Share on other sites More sharing options...
Third_Degree Posted October 3, 2008 Share Posted October 3, 2008 Have you sent the correct headers? Link to comment https://forums.phpfreaks.com/topic/126855-file-formatting/#findComment-656128 Share on other sites More sharing options...
lional Posted October 3, 2008 Author Share Posted October 3, 2008 what headers do I need to send? Link to comment https://forums.phpfreaks.com/topic/126855-file-formatting/#findComment-656130 Share on other sites More sharing options...
Third_Degree Posted October 6, 2008 Share Posted October 6, 2008 If I recall you probably need to add headers along the lines of Content-Type Content-Disposition Link to comment https://forums.phpfreaks.com/topic/126855-file-formatting/#findComment-657924 Share on other sites More sharing options...
ibechane Posted October 6, 2008 Share Posted October 6, 2008 Are you hoping to read in for the purpose of outputting to a browser? Unfortunately, Word documents are proprietary. They do not use HTML to markup the files, so you cannot just read in a word document and output it. If it is a Word 2007 document (.docx, I think) then you may be able to parse through the file, but it will be a lot of work converting it to HTML. You might be able to find a prewritten class somewhere, but I don't know if it exists. Try google. I wouldn't hold my breath. Link to comment https://forums.phpfreaks.com/topic/126855-file-formatting/#findComment-657928 Share on other sites More sharing options...
lional Posted October 6, 2008 Author Share Posted October 6, 2008 It does not need to be word, it can be text files but I want to write a site where the client can change the test, so I need to keep the formatting such as new lines, paragraphs etc Link to comment https://forums.phpfreaks.com/topic/126855-file-formatting/#findComment-657945 Share on other sites More sharing options...
ibechane Posted October 6, 2008 Share Posted October 6, 2008 When you're outputting the HTML, put your read-in text in pre tags, which tells the browser that the surrounded text is preformatted, meaning that the white space new lines, indents, etc, matter. Keep in mind that by default, the pre tags will output text in a fixed width font, like Courier. To change it, you need to use CSS to specify the font. Example: <html> <body> <pre style="font-family: Verdana"> Hello. I am preformatted text. This line will be indented. This line will be indented less, with three blank lines above </pre> </body> </html> Just echo all of that like you normally would in PHP, but with those extra pre tags. This method works best with regular text-files. This solution alone does not solve the problem of special formatting, like bold-face or underline. For that, you might just teach your client to use < b ></ b > and < u ></ u > tags. It's not that much trouble. Link to comment https://forums.phpfreaks.com/topic/126855-file-formatting/#findComment-658015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.