note 116781 added to book.simplexml
| From: | Serge | Date: | Thu, 26 Feb 2015 22:58:57 +0000 |
| Subject: | note 116781 added to book.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201818@lists.php.net to get a copy of this message | ||
XML data values should not contain "&" and that need to be replaced by html-entity
"&"
You can use this code to replace lonely "&" to "&":
<?php
$sText = preg_replace('#&(?![a-z]{1,6};)#i', '&', $sText);
?>
This will replace just "&" into "&" but dont touches other
html-entities like " ", "<" etc and, of course,
"&".
P.S. In regexp max length is 6 becouse I found that is the maximum length of possible html entity
using this code:
<?php
max(array_map('strlen', array_values(get_html_translation_table(HTML_ENTITIES, ENT_QUOTES
| ENT_HTML5)))) - 2
?>
minus two is for first "&" and last ";" in an any html entity.
----
Server IP: 72.52.91.14
Probable Submitter: 176.36.73.22
----
Manual Page -- http://php.net/manual/en/book.simplexml.php
Edit -- https://master.php.net/note/edit/116781
Del: integrated -- https://master.php.net/note/delete/116781/integrated
Del: useless -- https://master.php.net/note/delete/116781/useless
Del: bad code -- https://master.php.net/note/delete/116781/bad+code
Del: spam -- https://master.php.net/note/delete/116781/spam
Del: non-english -- https://master.php.net/note/delete/116781/non-english
Del: in docs -- https://master.php.net/note/delete/116781/in+docs
Del: other reasons-- https://master.php.net/note/delete/116781
Reject -- https://master.php.net/note/reject/116781
Search -- https://master.php.net/manage/user-notes.php