Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Simple JSON encoder

javascript json

Best Answer Vaielab , 09 September 2014 - 05:53 AM

Hi there

 

You seem to are searching for a addslashes function in javascript

If this is the case, take a look at this function http://phpjs.org/functions/addslashes/

function addslashes(str) {
  //  discuss at: http://phpjs.org/functions/addslashes/
  // original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // improved by: Ates Goral (http://magnetiq.com)
  // improved by: marrtins
  // improved by: Nate
  // improved by: Onno Marsman
  // improved by: Brett Zamir (http://brett-zamir.me)
  // improved by: Oskar Larsson Högfeldt (http://oskar-lh.name/)
  //    input by: Denny Wardhana
  //   example 1: addslashes("kevin's birthday");
  //   returns 1: "kevin\\'s birthday"

  return (str + '')
    .replace(/[\\"']/g, '\\$&')
    .replace(/\u0000/g, '\\0');
}

This will add the slashes to your url

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 jasonalien

jasonalien

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 194 posts

Posted 09 September 2014 - 05:30 AM

Hello there, 

 

I want to have a function that turns this : 

 

http://examplesite.com/folders/images/myphoto.jpg 

 

to this : 

 

http:\/\/examplesite.com\/folders\/images\/myphoto.jpg 

 

Can any of you help me with that? I'm not that good at JS but I need this : /

 

Thanks.


Edited by jasonalien, 09 September 2014 - 05:32 AM.


#2 Vaielab

Vaielab

    Programming God

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1382 posts

Posted 09 September 2014 - 05:53 AM   Best Answer

Hi there

 

You seem to are searching for a addslashes function in javascript

If this is the case, take a look at this function http://phpjs.org/functions/addslashes/

function addslashes(str) {
  //  discuss at: http://phpjs.org/functions/addslashes/
  // original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  // improved by: Ates Goral (http://magnetiq.com)
  // improved by: marrtins
  // improved by: Nate
  // improved by: Onno Marsman
  // improved by: Brett Zamir (http://brett-zamir.me)
  // improved by: Oskar Larsson Högfeldt (http://oskar-lh.name/)
  //    input by: Denny Wardhana
  //   example 1: addslashes("kevin's birthday");
  //   returns 1: "kevin\\'s birthday"

  return (str + '')
    .replace(/[\\"']/g, '\\$&')
    .replace(/\u0000/g, '\\0');
}

This will add the slashes to your url


You can now stalk me on linkedin: http://ca.linkedin.c...elle/24/b44/88/ !





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download