Created
August 3, 2018 17:39
-
-
Save quisido/88ce106b568d638486b9a7783749da0f to your computer and use it in GitHub Desktop.
PHP's htmlspecialchars implemented in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /********************************\ | |
| |* Translating ampersand first: *| | |
| \********************************/ | |
| var string = '<'; // < | |
| string = string.replace(/&/g, '&'); // < | |
| string = string.replace(/</g, "<"); // < | |
| /*******************************\ | |
| |* Translating ampersand last: *| | |
| \*******************************/ | |
| var string = "<"; // < | |
| string = string.replace(/</g, "<"); // < | |
| string = string.replace(/&/g, "&"); // &lt; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment