kicks66 Posted March 26, 2014 Share Posted March 26, 2014 I have the following values: The Iskelé Jones & Sons I am trying to remove any special characters (namely the &). Using str_replace with '&' gives me the following: The Iskelé Jones #038; Sons When in reality I would like to get: The IskeleJones Sons What conversions do I need to do in order to achieve this? Link to comment https://forums.phpfreaks.com/topic/287287-removing-and-special-characters/ Share on other sites More sharing options...
denno020 Posted March 26, 2014 Share Posted March 26, 2014 How are you using str_replace? str_replace(' & ', ' ', $variable); Should do the job fine.. Grabbing the space from either side of the & symbol and replacing with 1 space will fix a problem if you simply find the & symbol and replace it with nothing. Link to comment https://forums.phpfreaks.com/topic/287287-removing-and-special-characters/#findComment-1473940 Share on other sites More sharing options...
Ch0cu3r Posted March 26, 2014 Share Posted March 26, 2014 Using str_replace with '&' gives me the following: The Iskelé Jones #038; Sons If you are getting that result then & symbols have most likely been html encoded to & In which case you'll need use str_replace with & instead $text = str_replace('&', '', $text); Or use html_entity_decode prior to str_replace and then apply htmlentities again afterwards Link to comment https://forums.phpfreaks.com/topic/287287-removing-and-special-characters/#findComment-1473946 Share on other sites More sharing options...
ginerjm Posted March 26, 2014 Share Posted March 26, 2014 Just to point out - changing something from "Jones & Sons" to "Jones Sons" really makes for a confusing expression. If I named my company as such I wouldn't like to see it changed to something with less meaning/identity. Link to comment https://forums.phpfreaks.com/topic/287287-removing-and-special-characters/#findComment-1473962 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.