Jump to content

Escaping Double Quotes [Solved]


SharkBait

Recommended Posts

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

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-132

the
[code]
oFCKeditor.value = '{$my_database_entry_text_ here}';
[/code]


[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]

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.