Created
August 12, 2015 22:24
-
-
Save zachwills/3bd14f489b9e962f7e15 to your computer and use it in GitHub Desktop.
Clean UTF8 WordPress HTML string for XML use.
This file contains 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
/** | |
* Clean utf8 HTML string for XML. | |
* | |
* | |
* @param string $string HTML string you want to make XML safe. | |
*/ | |
function clean_html_for_xml( $string ) { | |
$string = strip_tags( $string ); | |
$string = htmlspecialchars( $string ); | |
$string = strip_shortcodes( $string ); | |
// http://stackoverflow.com/questions/12229572/php-generated-xml-shows-invalid-char-value-27-message | |
return preg_replace ( '/[^\x{0009}\x{000a}\x{000d}\x{0020}-\x{D7FF}\x{E000}-\x{FFFD}]+/u', ' ', $string ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment