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
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.

Link to comment
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.