[thelist] Converting formatting between text field and html file
mike karthauser
mikek at brightstorm.co.uk
Wed Oct 29 09:14:24 CST 2003
I have got a basic content management script that allows you to take the
contents of an include file, load it into a text box, edit it and resave it.
My php script converts <p>s to double new lines and <br> to single newlines
in the same way that wysiwyg editors do it. I intent to keep all html
formatting apart from the <p> and <BR> tags as most of the time all we are
trying to do is add new paragraphs to straight text. The styles are
controlled by external css.
What I am having problems with is differentiating between wrapped lines in
the textarea and user inserted line breaks (ie hitting return).
Heres what I got so far: (in php)
// strip the slashes
$ncontents = stripslashes($contents);
// do the p substitution
$des=ereg_replace(" "," ",$ncontents);
$des=ereg_replace("\r\n","<br>",$des);
$des=ereg_replace("\r","",$des);
$des=ereg_replace("<br><br>","</P><P>",$des);
$des=ereg_replace("<P><br>","<P>",$des);
$des=ereg_replace("<br>","\n",$des);
$des=ereg_replace("</li><br><li>","</li>\n<li>",$des);
$des=ereg_replace("</li><li>","</li>\n<li>",$des);
$des=ereg_replace("<br><ul>","\n<ul>",$des);
$des=ereg_replace("</P><P>","\n\n",$des);
$ncontents=ereg_replace("<br>","\n",$des);
Which is a bit long winded. Does anyone else use something like this they
can share?
Many thanks
--
Mike Karthauser
Managing Director - Brightstorm Ltd
Email >> mikek at brightstorm.co.uk
Web >> http://www.brightstorm.co.uk
Tel >> 0117 9426653 (office)
07939 252144 (mobile)
Snailmail >> Unit 8, 14 King Square,
Bristol BS2 8JJ
More information about the thelist
mailing list