[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 646
  • Last Modified:

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?
0
Frylock
Asked:
Frylock
1 Solution
 
ZylochCommented:
Hi Frylock,

Try this:

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

Regards,
Zyloch
0
 
FrylockAuthor Commented:
No effect, zyloch.
0
 
FrylockAuthor Commented:
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.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ZylochCommented:
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);
?>
0
 
FrylockAuthor Commented:
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.
0
 
ZylochCommented:
What is oFCKeditor exactly? Is it a textbox or?
0
 
FrylockAuthor Commented:
It create a WISYWIG style text area. www.fckeditor.com
0
 
ZylochCommented:
Have you tried hardcoding a value with a \' in it?
0
 
FrylockAuthor Commented:
Yep. I hardcoded that exact line at the value property sans the line breaks and it worked fine.
0
 
ZylochCommented:
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...
0
 
FrylockAuthor Commented:
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.
0
 
ZylochCommented:
Hmm... I do not get this at all. Try echoing out

urlencode($body);

just to see what's in there...
0
 
GrandSchtroumpfCommented:
This is pretty much like what has been suggested before, but it uses the "str_replace" method.

$body = str_replace("\n", " ", $body);
$body = str_replace("\r", " ", $body);
oFCKeditor.Value =  '<? echo addslashes($body) ;  ?>' ;
0
 
designbaiCommented:
try replacing the line breaks \n with <br> using nl2br

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

thanks.
0
 
FrylockAuthor Commented:
Zyloch - the URLENCODE returns absolutly nothing.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now