Hello João,

On 15 Jan 2004 at 17:07, João Cândido de Souza Neto wrote:

> I'm using str_replace("\r\n","\\r\\n",addslashes($campo)) to add "\" in
> mysql data to send to javascript variable.
> 
> Running in my machine with win xp + iis it's all ok, but in server with
> linux + apache, the javascript variable no have "\" causing error in my
> script.
> 
> Anybody know how do i do ?

(a) Have you tried mysql_escape_string() instead of addslashes() to escape your 
string? 
It will automatically escape line breaks and carriage returns as well as single and 
double quotes and backslashes. Mind you, mysql_escape_string() can be used even if 
your database is not MySQL.

(b) Have you considered that when you use double-quotes around a string (rather than 
single-quotes) \r and \n get parsed and when you use single-quotes they don't? This 
may have nothing to do with the problem you're experiencing and I may be saying 
something stupid, but it might be worth looking into this issue.

Good luck,

Erik

Reply via email to