tags:

views:

20

answers:

1

Hey, i noticed when my ajax response (msg) gets prepended and toggled, if it contains " or ' it turns out \" and \'.

How can i fix this?

A: 

Show us your server side code.

but it looks like your using addslashes on the content before your sending it.

for example

$string = "I love biscuit's";

$string = addslashes($string); //I love biscuit\'s

//now its slashed, remove them
$string = stripslashes($string); // I love biscuit's
RobertPitt
i have nl2br($message) and $message is the mysql_real_escape_string($_POST['message']);
Karem
You should only use `mysql_real_escape_string` when you're creating an SQL query from the value. When you're echoing output back to the browser it should not be SQL-escaped; if you're returning HTML, though, you will certainly need to HTML-escape it (with `htmlspecialchars()` before calling `nl2br()`).
bobince
I am putting $message in the DB thats why i am using mysql_real_escape.. i tried echo $message; only without nl2br, and it still do \" .. Also tried echo htmlspecialchars($message), still no result
Karem
`mysql_real_escape_string` should **only** ever be used for escaping data before the database, for content within html output you should use `htmlspecialchars`
RobertPitt
ok just did another variable $printmsg = htmlspecialchars($_POST['message']); and then echo nl2br($printmsg), works good with ' / and so, but when i try " i get "
Karem