I have an array filled with strings, a value can for example be "not updated for > days". I use the values in the array to create some url's and need to remove the /\<> and other illegal URL characters. How do I easiest do this?
I started with
var Name0 = title[0].substring(1).replace(" ", "%20").replace("/", "") + '.aspx'; var Name1 = title[1].substring(1).replace(" ", "%20").replace("/", "") + '.aspx'; and so on but can I do this in a better way?
Thanks in advance.
If you wish to keep the symbols in the URI, but encode them:
encodedURI = encodeURIComponent(crappyURI);
If you wish to build 'friendly' URIs such as those on blogs:
niceURI = crappyURI.replace(/[^a-zA-Z0-9-_]/g, '');
You could use the encodeURIComponent function which will properly URL encode the value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With