Jump to content

Removing & and Special Characters


kicks66

Recommended Posts

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 Iskele
Jones 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

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.

 

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.