The Little Guy Posted December 29, 2008 Share Posted December 29, 2008 Is there a function that will remove all htmlentites from a string? If not, how can I do that? Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/ Share on other sites More sharing options...
Mchl Posted December 29, 2008 Share Posted December 29, 2008 You want to remove them, or decode them? Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725386 Share on other sites More sharing options...
The Little Guy Posted December 29, 2008 Author Share Posted December 29, 2008 I want to completely remove them. B.T.W. If anyone has the power could you move this to the "PHP Help" board, thanks! Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725392 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 Are you looking for strip_tags? Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725398 Share on other sites More sharing options...
The Little Guy Posted December 29, 2008 Author Share Posted December 29, 2008 well, I used that, but I still have the entities, such as © " etc. in my output. Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725405 Share on other sites More sharing options...
.josh Posted December 29, 2008 Share Posted December 29, 2008 perhaps you can throw html_entity_decode into the mix? Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725408 Share on other sites More sharing options...
Mchl Posted December 29, 2008 Share Posted December 29, 2008 You could use preg_replace to remove everything between & and ; (just don't ask me for the pattern for that... I'm regexp challenged) Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725409 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 perhaps you can throw html_entity_decode into the mix? I think he wants to completely remove them not decode them. I want to completely remove them. Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725413 Share on other sites More sharing options...
.josh Posted December 29, 2008 Share Posted December 29, 2008 perhaps you can throw html_entity_decode into the mix? I think he wants to completely remove them not decode them. I want to completely remove them. well I was thinking more along the lines of decoding, then using something else to remove the decoded stuff, hence the whole "throw it into the mix" thing. Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725414 Share on other sites More sharing options...
.josh Posted December 29, 2008 Share Posted December 29, 2008 anyways, if you want to go the preg_replace route, you could do $string = "&foo; something blah blah &bar; something"; $string = preg_replace("~&[^;]*;~","",$string); Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725418 Share on other sites More sharing options...
The Little Guy Posted December 29, 2008 Author Share Posted December 29, 2008 as I am have been thinking, I think I would like to keep some of the entities. I would like to remove all of the entities that would be useless if you were to do a search, on the database, such as: quot, copy, apos, etc. I would like to keep amp and any other commonly searched for decoded entities. Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725422 Share on other sites More sharing options...
.josh Posted December 29, 2008 Share Posted December 29, 2008 okay so you either need to make a whitelist of the ones you want to keep, or else the ones you want removed. Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725427 Share on other sites More sharing options...
The Little Guy Posted December 29, 2008 Author Share Posted December 29, 2008 I think the "Keep" list would be shorter, So... not sure how I would do that... Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725438 Share on other sites More sharing options...
Mchl Posted December 29, 2008 Share Posted December 29, 2008 str_replace ? Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725446 Share on other sites More sharing options...
Maq Posted December 29, 2008 Share Posted December 29, 2008 as I am have been thinking, I think I would like to keep some of the entities. I would like to remove all of the entities that would be useless if you were to do a search, on the database, such as: quot, copy, apos, etc. I would like to keep amp and any other commonly searched for decoded entities. If the purpose of this is for a search, why can't you just decode the entities when you're comparing against the database? Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725456 Share on other sites More sharing options...
.josh Posted December 29, 2008 Share Posted December 29, 2008 I think the "Keep" list would be shorter, So... not sure how I would do that... well, for instance, you can do something like this: $keepers = array('(amp)','(bar)'); $string = "&foo; something blah & blah &bar; something &blah;"; $keep = implode ("|",$keepers); $string = preg_replace("~&(?!".$keep.")[^;]*;~","",$string); Link to comment https://forums.phpfreaks.com/topic/138740-htmlentites-remove/#findComment-725460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.