Created
April 12, 2017 09:02
-
-
Save gkralik/3bc4a56fcd0f385899a00f951269f803 to your computer and use it in GitHub Desktop.
PHP: embed string in CDATA section
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
function embedInCData($str) | |
{ | |
$dom = new \DOMDocument(); | |
$cdata = $dom->createCDATASection($str); | |
return $dom->saveXML($cdata); | |
} | |
// usage: | |
echo embedInCData('<strong>foobar</strong>'); | |
// <![CDATA[<strong>foobar</strong>]]> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment