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


Link to comment
Share on other sites

[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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.