SharkBait Posted December 11, 2006 Share Posted December 11, 2006 What do I need to use to escape double quotes?The javascript online editor I use needs double quoetes (") escaped with a backslash.Can I [code=php:0]str_replace('"', '\"', $_POST['body'])[/code] or is there something else I need to look at?Would [code=php:0]addslashes()[/code] escape double quotes? I'd also need to replace \n and \r characters with I suppose <br /> instead.Thanks Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/ Share on other sites More sharing options...
Psycho Posted December 11, 2006 Share Posted December 11, 2006 What you are trying to accomplish is not very clear. Please give an example of what would be in $_POST['body'] and what you want to translate that to. Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139258 Share on other sites More sharing options...
The Little Guy Posted December 11, 2006 Share Posted December 11, 2006 add slashes adds slashes to ' and to " maybe this for the second part:preg_replace("~^\n$|^\r$~","I suppose ",$_POST['my_str']); Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139262 Share on other sites More sharing options...
SharkBait Posted December 11, 2006 Author Share Posted December 11, 2006 Ok I gues using $_POST[] wasnt the best example.When I edit my blog entries the javascript editor I use online (FCKeditor) requires that if I have a pre-existing entry in the textarea, that I escape all double quotes and get rid of any \r \n it has in the message.So when I pull the information from the database to be displayed on my editing page I have to make sure that the javascript doesn't freak out.This is the section I am trying to abide by: http://wiki.fckeditor.net/Developer%27s_Guide/Integration/Javascript#line-132the[code]oFCKeditor.value = '{$my_database_entry_text_ here}';[/code] Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139272 Share on other sites More sharing options...
SharkBait Posted December 12, 2006 Author Share Posted December 12, 2006 [quote author=The Little Guy link=topic=118206.msg482920#msg482920 date=1165871698]add slashes adds slashes to ' and to " maybe this for the second part:preg_replace("~^\n$|^\r$~","I suppose ",$_POST['my_str']);[/quote]So something like this?[code]<?php$body = addslashes($entry['body']);preg_replace("~^\n$|^\r$~","<br />", $body);?>[/code] Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139664 Share on other sites More sharing options...
The Little Guy Posted December 12, 2006 Share Posted December 12, 2006 yeah... That should workIf not... Then take out the $ signs and try that Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139778 Share on other sites More sharing options...
ted_chou12 Posted December 12, 2006 Share Posted December 12, 2006 can you teach me how to install the javascript online editor please..? ^^ Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139782 Share on other sites More sharing options...
The Little Guy Posted December 12, 2006 Share Posted December 12, 2006 [quote author=ted_chou12 link=topic=118206.msg483446#msg483446 date=1165947240]can you teach me how to install the javascript online editor please..? ^^[/quote]What does that have to do with this topic? Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139786 Share on other sites More sharing options...
hitman6003 Posted December 12, 2006 Share Posted December 12, 2006 I think he means one of the WYSIWYG text editors, such as TinyMCE or FCKeditor. Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139787 Share on other sites More sharing options...
ted_chou12 Posted December 12, 2006 Share Posted December 12, 2006 because i am having some trouble installing the online javascript editor into the form... :'( Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139788 Share on other sites More sharing options...
The Little Guy Posted December 12, 2006 Share Posted December 12, 2006 start a new thread. Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-139795 Share on other sites More sharing options...
SharkBait Posted December 13, 2006 Author Share Posted December 13, 2006 I tried this and it seemed to work:[code]$body = preg_replace("((\r\n)+)", " ", trim($body));[/code]Though you're code might of worked too, I think i was forgetting to actualyl assign the preg_replace to $body ;)Thanks for the help it works the way I need it to now! Link to comment https://forums.phpfreaks.com/topic/30253-escaping-double-quotes-solved/#findComment-140433 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.