Security Notice: The following should not be necessary any longer for you
If you don’t have PHP 5.2 you can use something like this:
function js_str($s) { return '"' . addcslashes($s, "\0..\37\"\\") . '"'; } function js_array($array) { $temp = array_map('js_str', $array); return '[' . implode(',', $temp) . ']'; } echo 'var cities = ', js_array($php_cities_array), ';';
Related Posts:
- How to prevent the “Confirm Form Resubmission” dialog?
- Difference between “as $key => $value” and “as $value” in PHP foreach
- Array to String PHP?
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
- Is SAJAX dead? What to replace with?
- Convert a PHP object to an associative array
- How to echo or print an array in PHP?
- How to call a JavaScript function from PHP?
- Is SAJAX dead? What to replace with?
- Deleting an element from an array in PHP
- How to insert an item at the beginning of an array in PHP?
- How to call a JavaScript function from PHP?
- How do I pass JavaScript variables to PHP?
- what is a good method to sanitize the whole $_POST array in php?
- Sort array of objects by object fields
- Returning JSON from PHP to JavaScript?
- In_array not working
- PHP multidimensional array search by value
- Fatal error: Cannot use object of type mysqli_result
- php foreach with multidimensional array
- PHP reindex array?
- php – How do I fix this illegal offset type error
- Mysql where id is in array
- How to convert array to SimpleXML
- Array of PHP Objects
- Is there a function to make a copy of a PHP array to another?
- How to Sort a Multi-dimensional Array by Value
- PHP array printing using a loop
- Fastest way to implode an associative array with keys
- How to close Browser Tab After Submitting a Form?
- PHP array delete by value (not key)
- JavaScript equivalent of PHP’s in_array()
- Access PHP variable in JavaScript
- PHP Multiple Checkbox Array
- Display array values in PHP
- Reset PHP Array Index
- How to push both value and key into PHP array
- Remove empty array elements
- How can you use php in a javascript function
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- For-each over an array in JavaScript
- Replace ' and similar html codes with their correspondent character?
- How to append something to an array?
- Google Calendar API event update always return 404 “not found” error
- navigate back with PHP form submission
- Sorting an array of objects by property values
- How do I check if an array includes a value in JavaScript?
- How to set 777 permission on a particular folder? [closed]
- How do I make a redirect in PHP?
- List of All Locales and Their Short Codes?
- How do I get a YouTube video thumbnail from the YouTube API?
- What is a slug?
- Visual list of all installed fonts with respective pangram phrase?
- Loop through an array in JavaScript
- How to add elements to an empty array in PHP?
- Loop through an array in JavaScript
- How to avoid Request Entity Too Large 413 error
- How to log in to phpMyAdmin with WAMP, what is the username and password?
- How can I remove a specific item from an array?
- Find object by id in an array of JavaScript objects
- How can I access and process nested objects, arrays or JSON?
- Should I use mysqli_real_escape string() or mysql_real_escape_string() for form data?
- Go Back to Previous Page
- count() parameter must be an array or an object that implements countable in laravel
- regex match any whitespace
- Split string into array
- How can I remove a specific item from an array?
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- Array.size() vs Array.length
- How to fix “Headers already sent” error in PHP
- Sort array of objects by string property value
- How to pop an alert message box using PHP?
- currently unable to handle this request HTTP ERROR 500
- Copy array by value
- How can I reverse an array in JavaScript without using libraries?
- PHP page redirect
- “Notice: Undefined variable”, “Notice: Undefined index”, and “Notice: Undefined offset” using PHP
- What is the way of declaring an array in JavaScript?
- Whoops, looks like something went wrong. Laravel 5.0
- PHP “or” Syntax
- How to create an associative array in JavaScript literal notation
- Fatal error: Call to undefined function mysql_connect()
- How to fix “Headers already sent” error in PHP
- Loop through an array php
- What are namespaces?
- Remove duplicate values from JS array [duplicate]
- How can I create a two dimensional array in JavaScript?
- How to loop through an array containing objects and access their properties
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- Get the last item in an array
- Get the full URL in PHP
- How do I empty an array in JavaScript?
- Remove duplicate values from JS array
- PDOException SQLSTATE[HY000] [2002] No such file or directory
- How can I create a two dimensional array in JavaScript?
- http://localhost:80 is not working on running Apache server through UniServer ZeroXIII
- PDOException SQLSTATE[HY000] [2002] No such file or directory
- Javascript Uncaught TypeError: Cannot read property ‘0’ of undefined
- Mysql query- How to use contains?
- How to loop through an array containing objects and access their properties