Programming Tools
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingProgramming Tools

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 3rd, 2002, 08:35 AM
baddogg99 baddogg99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: GA, USA
Posts: 19 baddogg99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #2  
Old December 3rd, 2002, 03:13 PM
JXL JXL is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Netherlands
Posts: 13 JXL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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); 

Reply With Quote
  #3  
Old December 3rd, 2002, 06:04 PM
Joe4JC Joe4JC is offline
The name's Joe. Yours?
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Location: Lurking in the shadows...
Posts: 147 Joe4JC User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Use str_replace instead of ereg - much faster

Cheers,
Joe of 4Life
__________________
Check out 4Life today!

Reply With Quote
  #4  
Old December 3rd, 2002, 06:27 PM
Lindset Lindset is offline
weirdomoderator
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Alta, Norway
Posts: 370 Lindset User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Send a message via ICQ to Lindset Send a message via AIM to Lindset
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

Reply With Quote
  #5  
Old December 4th, 2002, 06:38 AM
baddogg99 baddogg99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: GA, USA
Posts: 19 baddogg99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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....

Reply With Quote
  #6  
Old December 4th, 2002, 07:30 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
$value = str_replace('\r', '', str_replace('\n', '', $value));

Reply With Quote
  #7  
Old December 5th, 2002, 01:46 PM
dgibson dgibson is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Urbana, MD, USA
Posts: 66 dgibson User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
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.

Reply With Quote
  #8  
Old December 6th, 2002, 08:02 AM
baddogg99 baddogg99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: GA, USA
Posts: 19 baddogg99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #9  
Old November 7th, 2004, 05:11 PM
Rich4444 Rich4444 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 1 Rich4444 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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!

Reply With Quote
  #10  
Old December 7th, 2012, 06:38 PM
inetryconydot inetryconydot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Location: canada
Posts: 2 inetryconydot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 6 sec
Reputation Power: 0
Send a message via ICQ to inetryconydot Send a message via Skype to inetryconydot
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingProgramming Tools > [wysiwyg] remove line breaks/carriage returns


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap