Jump to content

auto format .txt files for web..?


ag3nt42

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

\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

Link to comment
Share on other sites

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

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

\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?

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.