Skip to content

Instantly share code, notes, and snippets.

@tabatkins
Forked from shakyShane/find_your_nearest.php
Created September 17, 2012 02:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tabatkins/3735297 to your computer and use it in GitHub Desktop.
Save tabatkins/3735297 to your computer and use it in GitHub Desktop.
HTML to Json
<?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