Categories
Coding

XtScript Function: addslashes

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.

<!--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-->
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?

By SiDar

Webmaster Assistant and Editor at Indotechboy.com.

SiDar enjoying himself listening J-pop genre music and playing games, especially old school games. Sometimes he also found watching anime and reading manga are interesting when his fellow author recommend him some good titles.

Leave a Reply

Your email address will not be published. Required fields are marked *