mattgleeson Posted January 14, 2007 Share Posted January 14, 2007 HiI need to display html stored in a database on web page but when I display the html I need to convert all html special charaters outside of html tags into html entities.The php functions htmlentities() etc don't do what I need as they seem to translate ALL applicable symbols to HTML entities. What I need is a function that is a bit smarter in that it only transalates applicable symbols that are OUTSIDE tags into HTML entities. Is there any php or even smarty functions that do this or can you give me some help/tips the best way to achieve this?Cheers Link to comment https://forums.phpfreaks.com/topic/34112-escaping-html-entities-outside-of-html-tags/ Share on other sites More sharing options...
Barand Posted January 14, 2007 Share Posted January 14, 2007 Something like[code]<?php$str = "<a href='abc.php?x=y&v=w'>Marks & Spencer</a>";$a = explode ('>', $str);foreach ($a as $k => $v) { if ($v{0} != '<') { $b = explode ('<', $v); $b[0] = htmlentities($b[0]); $a[$k] = join ('<', $b); }}$newstr = join ('>', $a);echo $newstr;?>[/code] Link to comment https://forums.phpfreaks.com/topic/34112-escaping-html-entities-outside-of-html-tags/#findComment-160465 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.