ironside82 Posted July 9, 2010 Share Posted July 9, 2010 Hi, I've a question on how to display a text document using PHP, I want to be able to display a formatted text document into part of my site using PHP, It doesn't matter what format the document is rtf, doc etc.. The file name of the text document is stored in a database and then recalled using PHP and displayed with all its correct formatting. I've tried using file_get_contents to recall an RFT file but that churns out a load of rubbish. As long as I can recall a file from a database and display it correctly I don't mind how it is done. Thanks in advance for you help James Quote Link to comment https://forums.phpfreaks.com/topic/207241-displaying-text-documents/ Share on other sites More sharing options...
Adam Posted July 9, 2010 Share Posted July 9, 2010 This isn't easy to do to support any format (or many different ones). PDF, RTF, DOC, etc. are all formatted, they aren't in plain text. PHP has a vairety of classes, libraries and extensions available on the net that you may be able to use, but each is likely to only support 1 format. Quote Link to comment https://forums.phpfreaks.com/topic/207241-displaying-text-documents/#findComment-1083537 Share on other sites More sharing options...
Wolphie Posted July 9, 2010 Share Posted July 9, 2010 I've been writing a DOCX and XML file to text converter in C. While I was doing some reading about XML conversion and parsing there was also a paragraph on RTF files. From what I can remember, parsing RTF files is extremely difficult to do. Example code of an RTF file from Wikipedia: {\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard This is some {\b bold} text.\par } Quote Link to comment https://forums.phpfreaks.com/topic/207241-displaying-text-documents/#findComment-1083542 Share on other sites More sharing options...
ironside82 Posted July 9, 2010 Author Share Posted July 9, 2010 I dont need to support multiple formats, Just one that works and is the easiest to implement, If RTF if tricky do you know of any other formats that would work? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/207241-displaying-text-documents/#findComment-1083547 Share on other sites More sharing options...
litebearer Posted July 9, 2010 Share Posted July 9, 2010 the first question should be WHO is creating the document Quote Link to comment https://forums.phpfreaks.com/topic/207241-displaying-text-documents/#findComment-1083549 Share on other sites More sharing options...
Wolphie Posted July 9, 2010 Share Posted July 9, 2010 XML is probably easier to support. PHP has a built-in XML parser. XML files can also be styled using CSS. Quote Link to comment https://forums.phpfreaks.com/topic/207241-displaying-text-documents/#findComment-1083552 Share on other sites More sharing options...
Adam Posted July 9, 2010 Share Posted July 9, 2010 the first question should be WHO is creating the document I don't think it should by WHO, but for what purpose. What will the file contain? I dont need to support multiple formats My bad. I misunderstood the following to mean it doesn't matter what format the user provides. It doesn't matter what format the document is rtf, doc etc.. Quote Link to comment https://forums.phpfreaks.com/topic/207241-displaying-text-documents/#findComment-1083566 Share on other sites More sharing options...
AbraCadaver Posted July 9, 2010 Share Posted July 9, 2010 If you don't need fancy formating then stick with text. If you do then HTML may be fine as it's easy for people to create in Word, etc.. and is easy to display: $conn = mysql_connect('host', 'user', 'password'); $result = mysql_query("SELECT `filename` FROM `dbname`.`tablename` WHERE something=something LIMIT 1"); $row = mysql_fetch_assoc($result); echo "<pre>" . file_get_contents($row['filename']) . "</pre>"; // for text files echo file_get_contents($row['filename']); // for HTML files Quote Link to comment https://forums.phpfreaks.com/topic/207241-displaying-text-documents/#findComment-1083633 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.