Jump to content

how to convert php string ro javascript string?


megetron

Recommended Posts

hi,

I would like to convert a php string like "that's all folks!" to javascript string "that\'s all folks", so I can write something like:

diocument.write('<?$myString?>');

so of course i can replace ' with \' with replace function but is there a php function that do this for the specific charachter and for other special charchters too?

 

what is the best way do this?

Thanks guys,

 

People call it twice because there's no way to tell if it's been called before, and there are built-in features of PHP (or used to be) that did it for you, so people ended up doubling or tripling up on slashes and it was a huge problem.

 

Not so much anymore thanks to magic_quotes being killed, but I still hate it.

Oh no it definitely would, I'm just prejudiced against addslashes because:

 

A)  There's always a better solution, addslashes was a hack from back in the day

 

B)  Addslashes combined with magic_quotes produced a significant number of threads in the PHP forums while it was still a default, and I got really sick of them

Some other encoding functions won't step on their own toes (and double-encode things), just in case they're called twice.  I thought mysql_real_escape_string wouldn't double-encode things, but requinix (privately) told me I would be wrong if I mentioned that.

 

So ignore that bit, I thought there were other algorithms that behaved more intelligently than they do.

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.