Use a PHP variable in your Javascript code
What if you’d like to use a PHP variable in your javascript code?
You can use this code in your javascript:
In order to use this PHP function, you need to have at PHP version 5.2.
What does this function do? This returns the JSON representation of a value. Take note that this function works only with data encoded in UTF-8.
Learn more about the function here.