Skip to content

Instantly share code, notes, and snippets.

@shakyShane
Created September 9, 2012 19:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shakyShane/3686856 to your computer and use it in GitHub Desktop.
Save shakyShane/3686856 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)
{
$html = str_replace(chr(10), "<br />", $html); //remove carriage returns
$html = str_replace(chr(13), "", $html);
$html = str_replace('"', '\'', $html); //remove any double quotes
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment