Jump to content

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.

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.