|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
[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! |
|
#2
|
|||
|
|||
|
ur talking about doing it in php right?
if so, try this: PHP Code:
|
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
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.... |
|
#6
|
|||
|
|||
|
$value = str_replace('\r', '', str_replace('\n', '', $value));
|
|
#7
|
|||
|
|||
|
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. |
|
#8
|
|||
|
|||
|
Thats it!
You just answered it. I was missing chr(10), was only replacing chr(13)... 10 was what I was looking for!
Thanks! |
|
#9
|
|||
|
|||
|
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! |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Programming Tools > [wysiwyg] remove line breaks/carriage returns |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|