Bottyz Posted October 8, 2010 Share Posted October 8, 2010 Hi all, I wrote this function: function nl2br_revertfull($str) { $br = preg_match('`<br>[\\n\\r]`',$str) ? '<br>' : '<br />'; $str = html_entity_decode(preg_replace('`'.$br.'([\\n\\r])`', '$1', $str)); $str = str_replace('&', '&', $str); return str_replace('£', '£', $str); } Which reverts nl2br & htmlencoded text from a db back for use in my webpage. All works beautifully except it seems if there are two <br /><br /> 's in a row it will only convert one and leave the other as <br />. So it looks like this in the source: <br /><br /> Can anyone see why? Thanks in advance!! Link to comment https://forums.phpfreaks.com/topic/215414-little-help-with-my-nl2br-reverting-function-needed/ Share on other sites More sharing options...
Pawn Posted October 8, 2010 Share Posted October 8, 2010 Why would you gunk up your data with <br />'s and HTML entities before storing it? Keep the database contents clean and use nl2br(); etc. when you actually display the data. Link to comment https://forums.phpfreaks.com/topic/215414-little-help-with-my-nl2br-reverting-function-needed/#findComment-1120152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.