note 71667 added to function.simplexml-load-file

From: Date: Sun, 10 Dec 2006 22:35:51 +0000
Subject: note 71667 added to function.simplexml-load-file
Groups: php.notes 
Request: Send a blank email to php-notes+get-120495@lists.php.net to get a copy of this message
In regards to Anonymous on 7th April 2006 There is a way to get back HTML tags. For example: <?xml version="1.0"?> <intro> Welcome to <b>Example.com</b>! </intro> <?php // I use @ so that it doesn't spit out content of my XML in an error message if the load fails. The content could be passwords so this is just to be safe. $xml = @simplexml_load_file('content_intro.xml'); if ($xml) { // asXML() will keep the HTML tags but it will also keep the parent tag <intro> so I strip them out with a str_replace. You could obviously also use a preg_replace if you have lots of tags. $intro = str_replace(array('<intro>', '</intro>'), '', $xml->asXML()); } else { $error = "Could not load intro XML file."; } ?> With this method someone can change the intro in content_intro.xml and ensure that the HTML is well formed and not ruin the whole site design. ---- Server IP: 85.116.0.130 Probable Submitter: 86.141.253.203 ---- Manual Page -- http://www.php.net/manual/en/function.simplexml-load-file.php Edit -- https://master.php.net/note/edit/71667 Del: integrated -- https://master.php.net/note/delete/71667/integrated Del: useless -- https://master.php.net/note/delete/71667/useless Del: bad code -- https://master.php.net/note/delete/71667/bad+code Del: spam -- https://master.php.net/note/delete/71667/spam Del: non-english -- https://master.php.net/note/delete/71667/non-english Del: in docs -- https://master.php.net/note/delete/71667/in+docs Del: other reasons-- https://master.php.net/note/delete/71667 Reject -- https://master.php.net/note/reject/71667 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#120495) next »