ag3nt42 Posted August 8, 2008 Share Posted August 8, 2008 Hello all, I've got a need to build a web app that will automatically format txt from a txt file.. I'm just wondering if there is already something out there that does this or if somone thinks this cannot be done.. Thanks for your thoughts, ~ag3nt42 Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/ Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 Just read the file in and format it...what's so hard about it? Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611602 Share on other sites More sharing options...
severndigital Posted August 8, 2008 Share Posted August 8, 2008 format it how?? if you simply want to put <BR>'s http://us2.php.net/manual/en/function.nl2br.php Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611606 Share on other sites More sharing options...
ag3nt42 Posted August 8, 2008 Author Share Posted August 8, 2008 I don't know I know i've tried before to get something like this to work and it never looks right on the page.. I mean I have people who have ABSOLUTELY NO IDEA how to code for the web.. basic HTML So my only option for them is to let them make a .txt file and drop it into a folder which then I'll have to have code setup to format it and paste it to the web. the nl2br() function won't work because you have to enter in \n for your line breaks. they do not want to have to do ANY coding. Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611611 Share on other sites More sharing options...
ag3nt42 Posted August 8, 2008 Author Share Posted August 8, 2008 Just read the file in and format it...what's so hard about it? nice dark.. so get_contents($FILE); format_for_web($FILE); right? Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611615 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 \n is automatically in textboxes when Return is pressed on the keyboard, so nl2br() should work in that regard. And yes actually, that's all you need to do pretty much: $file = file_get_contents('somefile.txt'); echo some_function_that_does_what_you_want($file); What do you actually want "formatted" in the file? I'll try to help out a bit with writing "some_function_that_does_what_you_want()". xD Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611617 Share on other sites More sharing options...
severndigital Posted August 8, 2008 Share Posted August 8, 2008 do they have access to ms word?? there are a few phpclasses that will format basic msWord files correctly for the web. The ones i've used in the past were very basic handled Bold, color, and alignment. that might be an option for you. what about having a form field for adding text with formatting options. If you allow them to simply upload txt files... you will have alot of work to format every text file correctly. Unless you train them on creating the text file exactly right .. i.e. Title on line one. empty line Start typing here. and suppose some wants a line or two bolded or italic. for example ... if you type a simple doc in wordpad and apply formatting, you need to save it as an rtf file so keep the formatting. when you open that file in notepad .. you would see something like this. {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Arial;}} {\colortbl ;\red255\green0\blue0;} {\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\b\f0\fs20 This is bold\b0\par \par This is not\par \par \cf1 This is a color\cf0\par } i suppose you could write a preg_replace function or class to parse through and swap out all the information... but you will still need to train the 'poster' on correctly saving the file and assume they are all using the same ansi or language codes. in my past experience, it's been easier to put tools in place that allow the user to easily format for the web, and correctly train them rather than spend countless hours writing band-aide functions. -C Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611630 Share on other sites More sharing options...
ag3nt42 Posted August 8, 2008 Author Share Posted August 8, 2008 \n is automatically in textboxes when Return is pressed on the keyboard, so nl2br() should work in that regard. And yes actually, that's all you need to do pretty much: $file = file_get_contents('somefile.txt'); echo some_function_that_does_what_you_want($file); What do you actually want "formatted" in the file? I'll try to help out a bit with writing "some_function_that_does_what_you_want()". xD well i guess really all it needs to do is keep the file exactly as the user wrote it. hold line breaks and spaces. the nl2br() is working without \n well thanks guys.. i guess this will just have to do and I'll have to make up some bbcode or something... quick question how would I do the thing where, like on these forums, you could highlight a string of words then click on the bbcode button and it wraps tags around it... how can I do that? Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611636 Share on other sites More sharing options...
severndigital Posted August 8, 2008 Share Posted August 8, 2008 the nl2br() is working without \n FYI .. it's not that nl2br() is working without \n. the \n is there you just don't see it. when the user hits the return key the \n command is entered automatically. **EDIT** for BBCODE formating, you would need a BBCODE Formatter or use Javascript to swap add the text. Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611646 Share on other sites More sharing options...
ag3nt42 Posted August 8, 2008 Author Share Posted August 8, 2008 well then they shouldn't put it in the examples.. cuz its just confusing. Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611648 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 What? It's in there so it functions correctly in the string for the example... Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611655 Share on other sites More sharing options...
ag3nt42 Posted August 8, 2008 Author Share Posted August 8, 2008 Sooo your saying if.. I was to say nl2br(' Something or other this. And then something or other that. '); the above would not work? Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611664 Share on other sites More sharing options...
DarkWater Posted August 8, 2008 Share Posted August 8, 2008 You pressed Return, didn't you? That puts \n in there. Try it. Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611668 Share on other sites More sharing options...
ag3nt42 Posted August 8, 2008 Author Share Posted August 8, 2008 See but thats what I'm saying tho.. if thats the case why isn't it in the explanation? I get the feeling everyones like "DUH! IDIOT" But yet stuff like this never gets explained. Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-611676 Share on other sites More sharing options...
wildteen88 Posted August 8, 2008 Share Posted August 8, 2008 The description for the nl2br function explains it quite well. Description string nl2br ( string $string ) Returns string with '<br />' inserted before all newlines. Also you might want to look into incorporating a Rich Text editor (such as FCKEditor or TinyMCE) rather than BBCode. Because if you're going to add BBCode you may as well teach your client HTML, as BBCode is basically HTML. Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-612004 Share on other sites More sharing options...
jonsjava Posted August 8, 2008 Share Posted August 8, 2008 a simpler function, which is built into HTML, is the <pre></pre> tags. If you are just wanting it to print to screen exactly as it shows up in the text file, this is the solution for you. Quote Link to comment https://forums.phpfreaks.com/topic/118789-auto-format-txt-files-for-web/#findComment-612017 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.