convert html speciale characters to htmlentities
Author: c.tamietto@pokerspa.it (c.tamietto)
I have stored in a database field a html content . then i need to translate speecial characters to html entities . I've tried in this way : p_html_entities = $replace(p_html_entities, 1, "‘", "‘", -1) p_html_entities = $replace(p_html_entities, 1, "’", "’", -1) p_html_entities = $replace(p_html_entities, 1, "“", "“", -1) p_html_entities = $replace(p_html_entities, 1, "”", "”", -1) p_html_entities = $replace(p_html_entities, 1, "•", "•", -1) p_html_entities = $replace(p_html_entities, 1, "–", "–", -1) p_html_entities = $replace(p_html_entities, 1, "™", "™", -1) is there a better way to do this job ? i've tried the functions $decode and $tometa but it doesn't work thank you for any answer
4 Comments
Local Administrator
Check out $string. I use this one to translate special characters from HTML to uniface string.
Author: Iain Sharp (i.sharp@pcisystems.co.uk)
Local Administrator
$string can convert html entities to a character, but (unfortunately) there's no $unstring functionality to do the opposite (at this moment).
You could, however, use (e.g.) a loop like this: for i = 128 to 255 p_html_entities = $replace(p_html_entities, 1, $string($concat("&#", i, ";")), $concat("&#", i, ";"), -1) endfor But maybe Iain was trying to hint at this? This is of course only useful if the html content is not "too big" (otherwise this most likely will have a negative impact on performance). Hope this helps.
Author: diseli (daniel.iseli@uniface.com)
Local Administrator
No, I'd gotten the wrong conversion, I was thinking from HTML to text not the other way around. Umm, use a dtd to put the field into XML, and then replace "&#" with "&;#" ?
Author: Iain Sharp (i.sharp@pcisystems.co.uk)
Local Administrator
Thanks, Iain. I guess that I might misunderstand the problem. Could it be that the forum editor already has done some conversions and the original code looks different? If you want to replace "&" by "&" then assigning the text to a Struct node and then create XML from the Struct (using structToXml) should also do the trick. But again, maybe I'm missing the point here? Sorry.
Author: diseli (daniel.iseli@uniface.com)