Re: nl2br problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2011-02-01 at 14:24 -0600, Donovan Brooke wrote:

> Daniel Brown wrote:
> [snip]
> >      Absolutely.  Look into employing TinyMCE or CKEditor (or the older
> > FCKEditor) so you don't have to do so much server-side processing.
> > This will only apply to pages moving forward, mind you, not for
> > displaying existing table data.  You'll need to make the determination
> > if it's right for your specific case.
> 
> 
> I probably should have went that route! I'm really bad about
> looking for existing solutions. ;-)  Instead, I
> I am using a conditional where if the content contains
> a table, then don't use nl2br... then I told the admin
> that if they use tables in their body content, then they will
> have to include the <br />'s themselves.
> 
> ---
> $t_tablecount = substr_count($t_body, '<table');
> $t_endtablecount = substr_count($t_body, '</table');
> 
> if (($t_tablecount > 0) && ($t_endtablecount > 0)) {
>    print "$t_body";
> } else {
>    print nl2br("$t_body");
> }
> ---
> 
> I guess that will work for now.
> 
> Donovan
> 
> 
> -- 
> D Brooke
> 


Is it that you're having <br/> tags inserted inside of <table></table>
tags but outside of <tr> and <td> tags?

If so, you could maybe run a final check over the whole output string
and check for any <br/> tags that immediately precede a cell or row tag.
It's a little sloppy but might work.

Failing that, you could maybe apply some css to preserve line breaks as
they were entered, although this may produce varying results depending
on the exact content:

div.content
{
    white-space: pre;
}

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux