note 88169 deleted from function.htmlentities by cmb

From: Date: Sun, 01 Dec 2019 08:34:50 +0000
Subject: note 88169 deleted from function.htmlentities by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-213306@lists.php.net to get a copy of this message
Note Submitter: gunter [dot] sammet [at] gmail [dot] com ---- Had a heck of a time to get my rss entities right. using htmlentities didn't work and using html_entity_decode didn't work either. Ended up writing a custom function to encode and decode. It might still need some work but I thought to share it because I couldn't find anything on the net. Always open for suggestions to improve it! Here it is: <?php $entity_custom_from = false; $entity_custom_to = false; function html_entity_decode_encode_rss($data) { global $entity_custom_from, $entity_custom_to; if(!is_array($entity_custom_from) || !is_array($entity_custom_to)){ $array_position = 0; foreach (get_html_translation_table(HTML_ENTITIES) as $key => $value) { //print("<br />key: $key, value: $value <br />\n"); switch ($value) { // These ones we can skip case '&nbsp;': break; case '&gt;': case '&lt;': case '&quot;': case '&apos;': case '&amp;': $entity_custom_from[$array_position] = $key; $entity_custom_to[$array_position] = $value; $array_position++; break; default: $entity_custom_from[$array_position] = $value; $entity_custom_to[$array_position] = $key; $array_position++; } } } return str_replace($entity_custom_from, $entity_custom_to, $data); } ?>

« previous php.notes (#213306) next »