Last active
November 28, 2015 15:54
-
-
Save nimmneun/b4f60d8760e9fcb35697 to your computer and use it in GitHub Desktop.
xmlify array (with CDATA) imho a nifty way to convert an array to an XML string =)
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 | |
| // Convert n-dimensinal array to xml style string & wrap CDATA. | |
| function xmlify($arr) | |
| { | |
| $str = null; | |
| foreach ($arr as $k => $v) { | |
| if (is_array($v)) { | |
| $str .= "<$k>" . xmlify($v) . "</$k>"; | |
| } else { | |
| if (preg_match('#[<>&\?\']#', $v, $m)) { | |
| $v = '<![CDATA[' . $v . ']]>'; | |
| } | |
| $str .= "<$k>" . $v . "</$k>"; | |
| } | |
| } | |
| return $str; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment