Forum Moderators: coopster
I have a simple form for my clients to enter in their weekly newsletter. This gets stored the DB (longtext).
When I "echo nl2br($TextFromDb);"
It appears fine in the browser however is full of errors when validated. I assume that this is due to my clients 'copy and pasting' text from MS Word (with all its quirky formating as well as the <br /> issue)
So I have had to do this:
$DisplayText = nl2br($TextFromDb);
$old=array("<br />","'","’", " – ", "‘", "…");
$new=array ("<br>","'","’", "– ", "‘", "…");
echo str_replace($old,$new,$DisplayText);
This now validates - however it seems like a crazy solution. Espeically for all the MS Word formatting variations that I may have to contend with later on.
Am I on the wrong track?
If I do have to continue this approach is their a function that includes all the known formatting changes needed?
Cheers
Sleepy
Do you anticipate needing to use Word for your code production for very long? Maybe you would consider using EditPad or TextPad or another text editor that can handle multiple large files. Word isn't adding anything of value as an HTML editor.
If the client simply must use Word for printable formatting and whatnot, perhaps they could save as a "text with line breaks" file and use that for the web, instead.
User fills out form.
Into db: nl2br(htmlspecialchars($FormData));
No translation necessary to read into an HTML page.
If you provide an editing option:
User requests editing page.
From db: str_replace("<br />","",html_entity_decode($FormData));
Dump that into a textarea. When they save, nl2br, etc. back into the db.