Define strings in javascript

text:
If you are using php, you can use the very efficient function json_encode to define the string.
/**
 * Returns a string as it would be encoded in js. Hence it's allowed to
 *  echo 'var apa = ' . pond_get_js_string("apa") . ";\n";
 * 
 * @param string $in_str
 * @return "js-string"
 */
function pond_get_js_string ($in_str)
{
    return json_encode($in_str);
}