Link to home
Start Free TrialLog in
Avatar of Frylock
Frylock

asked on

FCKEditor/PHP - Problem with Line Breaks echoed into the value property. NEed to get rid of them.

I am echoing into the value property of FCKeditor. Oddly, these line breaks originated from the fckeditor page where the text was entered and loaded into the database.

If you look at the code, you see this:

  oFCKeditor.Value =  '<? echo addslashes($body) ;  ?>' ;

If you look at the output, you see this:

  oFCKeditor.Value =  '<p>He said to the woman, &quot;Who is your favorite singer?&quot; </p>
<p>She responded, after looking at her mother\'s watch, &quot;Shirley Manson\'s voice is spectacular.&quot;<br/>
</p>' ;

Those line breaks bust the fckeditor. How can I remove them from the echo so this doesn't happen?
Avatar of Zyloch
Zyloch
Flag of United States of America image

Hi Frylock,

Try this:

<?php
$body = addslashes($body);
$body = preg_replace("/\n/","",$body);
echo($body);
?>

Regards,
Zyloch
Avatar of Frylock
Frylock

ASKER

No effect, zyloch.
Avatar of Frylock

ASKER

Zyloch - it still echoes:

  oFCKeditor.Value =  '<p>He said to the woman, &quot;Who is your favorite singer?&quot;</p>
<p>She responded, after looking at her mother\'s watch, &quot;Shirley Manson\'s voice is spectacular.&quot;<br/>
</p>' ;

Those linebreaks KILL the editor.
I don't think it's the line breaks. It's the \' you have... A quick fix for that would be to change it to:

oFCKeditor.Value =  "<p>He said to the woman, &quot;Who is your favorite singer?&quot;</p>
<p>She responded, after looking at her mother\'s watch, &quot;Shirley Manson\'s voice is spectacular.&quot;<br/>
</p>" ;

With double quotes, but if your db string has double quotes, it'll fail also.

Try this:

<?php
$body = preg_replace("/'/","&#39;",$body);
echo($body);
?>
Avatar of Frylock

ASKER

No, it's definitly the line breaks that kill it. I can test it by hard coding the "value" with it and without the line breaks - test it yourself.
What is oFCKeditor exactly? Is it a textbox or?
Avatar of Frylock

ASKER

It create a WISYWIG style text area. www.fckeditor.com
Have you tried hardcoding a value with a \' in it?
Avatar of Frylock

ASKER

Yep. I hardcoded that exact line at the value property sans the line breaks and it worked fine.
Hmm.. that's interesting. What about:

<?php
$body = addslashes($body);
$body = preg_replace("/\r\n/","",$body);
echo($body);
?>

Curious if that will get rid of the line break...
Avatar of Frylock

ASKER

No. The line in the source of the page, post processing, is still:

  oFCKeditor.Value =  '<p>He said to the woman, &quot;Who is your favorite singer?&quot;</p>
<p>She responded, after looking at her mother\'s watch, &quot;Shirley Manson\'s voice is spectacular.&quot;<br/>
</p>' ;

And that breaks it. Still.
Hmm... I do not get this at all. Try echoing out

urlencode($body);

just to see what's in there...
ASKER CERTIFIED SOLUTION
Avatar of GrandSchtroumpf
GrandSchtroumpf

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try replacing the line breaks \n with <br> using nl2br

$body = nl2br($body);
oFCKeditor.Value =  '<? echo addslashes($body) ;  ?>' ;

thanks.
Avatar of Frylock

ASKER

Zyloch - the URLENCODE returns absolutly nothing.