$data = array('name' => 'John Doe', 'age' => 30); $json = raw2js(json_encode($data)); echo "var person = {$json};";
$string = "This string has 'single quotes' and \"double quotes\""; $jsString = raw2js($string); echo "var message = '{$jsString}';";In this example, we have a string with both single and double quotes, which can cause issues when passing it to JavaScript. We pass the `$string` variable to the `raw2js` function to encode it into a JavaScript-friendly format. The resulting JavaScript code will contain a variable `message` that is a string with the original message, including both single and double quotes. Package library: This function is not a part of any PHP package or library, and needs to be defined manually.