-
-
Save tabatkins/3735297 to your computer and use it in GitHub Desktop.
HTML to 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 | |
/** | |
* | |
* ---------------------------------------------- | |
* HTML to JSON | |
* ---------------------------------------------- | |
* | |
* [Currently used in Wordpress to output HTML into a Google Maps InfoWindow correctly] | |
* | |
* Take output from a WYSIWYG editor and replace the carriage returns with line breaks. | |
* This will stop your Javascipts complaining about the whitespace. | |
* | |
* Example Usage: | |
* htmlToJson($post->post_content); | |
* | |
*/ | |
function htmlToJson($html) | |
{ | |
// remove carriage returns and double quotes | |
return str_replace(array(chr(10), chr(13), '"'), array("<br />", "", '\''), $html); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment