Last active
July 1, 2016 16:08
-
-
Save lenivene/f791f701783a04162534ad0a96b1adc2 to your computer and use it in GitHub Desktop.
Escape json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function esc_json( $json ) { | |
/** | |
* @var string $safe_json replace escapers | |
* @var array escapers | |
* @var array replacements | |
* | |
*/ | |
$safe_json = str_replace( | |
array( "\\", "/", "\"", "\n", "\r", "\t", "\x08", "\x0c" ), | |
array( "\\\\", "\\/", "\\\"", "\\n", "\\r", "\\t", "\\f", "\\b" ), | |
$json | |
); | |
return $safe_json; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment