AdRock Posted February 8, 2009 Share Posted February 8, 2009 I have used htmlentities for inserting into the database and I get what's in the database into a form for editing. Is there a way i can convert back to html but only what i want to convert back. I suppose the best way is to use str_replace() I want to keep images as they are in the database using <img src but everything else i want to convert back. What about converting it all back to html and use str_replace on the images to put them back to htmlentities? Quote Link to comment https://forums.phpfreaks.com/topic/144353-solved-converting-back-from-htmlentities/ Share on other sites More sharing options...
premiso Posted February 8, 2009 Share Posted February 8, 2009 html_entity_decode Quote Link to comment https://forums.phpfreaks.com/topic/144353-solved-converting-back-from-htmlentities/#findComment-757482 Share on other sites More sharing options...
.josh Posted February 8, 2009 Share Posted February 8, 2009 html_entity_decode Only works on a 'global' level; that is, you cannot specify for it to ignore some things. You would have to use some regex to convert only the ones you want. Unless your target tags will always have the same content (attributes, values, same order/format), you will have to use a real regex function like preg_replace, instead of str_replace. Quote Link to comment https://forums.phpfreaks.com/topic/144353-solved-converting-back-from-htmlentities/#findComment-757488 Share on other sites More sharing options...
AdRock Posted February 8, 2009 Author Share Posted February 8, 2009 i tried using preg_replace and it works when i just have a small test script but when i try using data from a database it doesn't work is this right? while ($row = $result->fetch()) { $data = $row['content']; $find = array ('/<img/', '/.jpg">/'); $replace = array ('<img', '.jpg">'); $content = preg_replace ($find, $replace, $data); } Quote Link to comment https://forums.phpfreaks.com/topic/144353-solved-converting-back-from-htmlentities/#findComment-757732 Share on other sites More sharing options...
.josh Posted February 8, 2009 Share Posted February 8, 2009 Try 's' modifier $find = array ('/<img/s', '/.jpg">/s'); Quote Link to comment https://forums.phpfreaks.com/topic/144353-solved-converting-back-from-htmlentities/#findComment-757741 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.