You can use the built-in method
encodeURIComponent() method encode all characters except the following:
A-Z a-z 0-9 - _ . ! ~ * ' ( )
Let's check out an example to understand how this method basically works:
<script> // URL unsafe string var item = "$url+/[email protected] #name;" // Encode item name and append to URL var url = "http://example.com/search.php?product=" + encodeURIComponent(item); document.write(url); // Prints: http://example.com/search.php?product=%24url%2B%2Funsafe%40item%20%23name%3B </script>
You can alternatively use the
encodeURI() method, which does not encode characters that have special meaning (reserved characters) for a URI e.g.
encodeURI() method encode all characters except the following:
A-Z a-z 0-9 ; , / ? : @ & = + $ - _ . ! ~ * ' ( ) #
The following example demonstrates how this method actually works:
<script> // Sample URL var url = "http://example.com/search.php?product=laptop&price=500#featured"; document.write(url); // Prints: http://example.com/search.php?product=laptop&price=500#featured </script>
CRUD Operation using PHP7 | MySql | PDOThis is a step by step PHP 7 & MySQL...
How to Install MongoDB on Ubuntu 16.04Today, Laravelcode share with you how to...
Form Validation in React16 with ExampleThis is a React form validation step by...
Laravel 8 - Auto Load More Data on Page Scroll with AJAX with ExampleHello Dev. This detailed article, wil...