|
 |
|
Dev Articles Community Forums
> Programming
> Programming Tools
|
[wysiwyg] remove line breaks/carriage returns
Discuss [wysiwyg] remove line breaks/carriage returns in the Programming Tools forum on Dev Articles. [wysiwyg] remove line breaks/carriage returns Programming Tools forum for discussing any topics that don't fit into the programming categories above. Find information on tools and utilities to increase any programmer's productivity.
|
|
 |
|
|
|
|

Dev Articles Community Forums Sponsor:
|
|
|

December 3rd, 2002, 07:35 AM
|
|
Junior Member
|
|
Join Date: Nov 2002
Location: GA, USA
Posts: 19
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
[wysiwyg] remove line breaks/carriage returns
I created a wysiwyg editor from the tutorial.
The editor then stores the content into the DB. However, after some tags, like a horizontal rule, there is a line break in the HTML code that the wysiwyg creates. This is no problem except that I use this code to populate a variable in a javascript on another page, and the line breaks are causing errors in the script. I just need to get rid of the breaks and either put a space there or nothing at all.
Is there some way to get rid of this before I insert it to the database, or remove it after I query it and use it in javascript? If so, what is the character that I should be looking for? I tried the ascii value for a CR and that didnt work. Again, I fear the line breaks are screwing up my javascripts....
Any ideas?
Thanks in advance for the help!
|

December 3rd, 2002, 02:13 PM
|
|
Junior Member
|
|
Join Date: Nov 2002
Location: Netherlands
Posts: 13
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
ur talking about doing it in php right?
if so, try this:
PHP Code:
/*
* its now replacing the line break with a space (" ")
* if u want to replace the line break with nothing:
* change " " into ""
*/
$text = ereg_replace("\n", " ", $text);
|

December 3rd, 2002, 05:04 PM
|
|
The name's Joe. Yours?
|
|
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
Use str_replace instead of ereg - much faster
Cheers,
Joe of 4Life 
__________________
Check out 4Life today!
|

December 3rd, 2002, 05:27 PM
|
|
weirdomoderator
|
|
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370
Time spent in forums: < 1 sec
Reputation Power: 11
|
|
|
Yep, Joe is right. If you don't need the power of a regular expression, you should use str_replace.. The same applies to split, etc...
__________________
Best Regards,
Håvard Lindset
|

December 4th, 2002, 05:38 AM
|
|
Junior Member
|
|
Join Date: Nov 2002
Location: GA, USA
Posts: 19
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
actually..
Actually I want to do it in Cold Fusion.
I used a similiar CF function and it did not work.
Code:
<cfset attributes.content = replace (attributes.content,"\r", " ", "ALL")>
<cfset attributes.content = replace(attributes.content,"\n", " ", "ALL")>
The code does not error, it just doesn't see any /r....
|

December 4th, 2002, 06:30 PM
|
|
Guest
|
|
Posts: n/a
Time spent in forums:
Reputation Power:
|
|
|
$value = str_replace('\r', '', str_replace('\n', '', $value));
|

December 5th, 2002, 12:46 PM
|
|
Contributing User
|
|
Join Date: May 2002
Location: Urbana, MD, USA
Posts: 66
Time spent in forums: < 1 sec
Reputation Power: 12
|
|
|
I don't understand why you're getting the error in the first place. I have used a similar WYSIWYG edit written from MSHTML and use javascript to populate it with the data pulled form a database and it doesn't cause any problems. What is the exact error you are getting?
To strip line breaks in CF, you need to use the CHR() function. I believe CHR(13)&CHR(10) represents a line break.
|

December 6th, 2002, 07:02 AM
|
|
Junior Member
|
|
Join Date: Nov 2002
Location: GA, USA
Posts: 19
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Thats it!
You just answered it. I was missing chr(10), was only replacing chr(13)... 10 was what I was looking for!
Thanks!
|

November 7th, 2004, 04:11 PM
|
|
Registered User
|
|
Join Date: Nov 2004
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Nice thread, thanks!
Awesome! You guys saved me some looking around here, because I was also stuck with this same situation.
I wanted to take text from a multiline text box from a user, and save that text on one line in a delimited text file, so
that later I could easily retrieve the entry from that text file and display it (for users add news to a entry page).
This is the code I used to diplay it nicely, it might need some additional tweaking!
Code:
//convert news to HTML encoding for saving
$htmlnews = htmlentities($_POST["news"]); //make remaining items html entries.
$htmlnews = nl2br($htmlnews); //add html line returns
$htmlnews = str_replace(chr(10), " ", $htmlnews); //remove carriage returns
$htmlnews = str_replace(chr(13), " ", $htmlnews); //remove carriage returns
The first line takes the actual inputfrom the user and adds htmlentities for all the quotes, &, etc.
The second line adds the "br" tags for the line returns when you output the data back
the third line and fourth line replace the line feeds as described above. I just route the output back into
the same variable, and then output it to a simple text file! Works like a charm!
Thanks again!
|

December 7th, 2012, 05:38 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Location: Canada
Posts: 2
Time spent in forums: 2 h 10 m 38 sec
Reputation Power: 0
|
|
|
Hello! Let me introduce myself!
Hello! I really liked your forum, especially this section. I just signed up and immediately decided to introduce myself, if I'm wrong section, ask the moderators to move the topic to the right place, hopefully it will take me well... My name is Anri, me 34 years, humourist and serious man in one person. I apologize for my English
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|