Old school Swatch Watches
/ /

XtScript Function: addslashes

Returns a string with backslashes before single quotes, double quotes, backslashes, and NULL

XtScript addslashes function will process a string and add a backslashes (\) before each single quotes ('), double quotes ("), backslashes (\), found on the string and NULL variable.

The most practical example of the XtScript addslashes function is when we are using a string in a Javascript code where single quote and double quote characters are reserved by Javascript function, then we can escape the string contains single quotes and double quotes using XtScript addslashes function.

XtScript addslashes function basic syntax:

<!--parser:xtscript-->
	call addslashes $val=...
<!--/parser:xtscript-->

Learn XtScript addslashes from examples

Using XtScript addslashes function to escape string contains single quotes and double quotes and print it in Javascript.

- Code:
<!--parser:xtscript-->
	var $dialogue = Do you know the song title of "Mother, how are you today". Or you didn't know?
	var $escaped_dialogue = call addslashes $val=$dialogue

	print Before addslashes: <b>$dialogue</b> <br/>
	print After addslashes: <b>$escaped_dialogue</b> <br/><br/>

	# Using the escaped string in Javascript document.write
	print <script>
	print document.write("Javascript document.write: $escaped_dialogue");
	print </script>
	<!--/parser:xtscript-->
- Result:
Before addslashes: Do you know the song title of "Mother, how are you today". Or you didn't know?
After addslashes: Do you know the song title of \"Mother, how are you today\". Or you didn\'t know?