Forum Moderators: coopster

Message Too Old, No Replies

Format problem

         

triangulum

10:58 am on Dec 10, 2006 (gmt 0)

10+ Year Member



I've written a little content management system to allow moderators of a campaign group to enter articles into a mysql database.

Everything works fine but every now and then the diplayed page throws a wobbly (everything out of line and all the fonts altered) when double quotes are used; it's really wierd because it only happens now and then. I even have one paragraph in the database with two quotes; if I remove one of the set of quotes the page displays fine!

I'm thinking it has something to do with the <div> tag I'm using to display the articles;

<div style="padding:30;padding-left:80;padding-right:70;padding-bottom:40;color:000000" class="tah11">

<h2><?php echo nl2br($articleheading);?></h2>
<br /><br />
<?php echo nl2br($articlebody);?>
</div>

justgowithit

2:46 pm on Dec 10, 2006 (gmt 0)

10+ Year Member



You need to replace the raw double-quote with '&quot' before entering into the DB.

str_replace('"', '&quot;', nl2br($articleheading))

str_replace('"', '&quot;', nl2br($articlebody))

Now when you call it from the DB to print to page it will display properly.

triangulum

3:01 pm on Dec 10, 2006 (gmt 0)

10+ Year Member



Thanks justgowithit

i have already done that with htmlspecialchars when text is stored to the database, so it is correctly put in there as '&quote', but it still causes the problem with page display.

justgowithit

3:16 pm on Dec 10, 2006 (gmt 0)

10+ Year Member



How about a little experiment. eliminate the double quotes by substituting a random character(s) before you run through htmlspecialchars and input into the DB.

For example:

$dbIn = str_replace('"', 'zz', nl2br($articleheading))

Then when printing to page:

$dbOut = str_replace('zz', '&quot;', nl2br($articleheading))

It's a bit of a hack but it's tough without seeing the whole process.