Trouble Replacing Apostrophe with Preg_Replace

NotJay picture NotJay · Oct 19, 2011 · Viewed 25.1k times · Source

I am attempting to remove apostrophes from text and it isn't really working. It's got to be something small.

$text = preg_replace('/\'/', '', $text);

That's what I am using right now to remove it. What am I doing wrong?

There is a series of these to remove special characters to turn them into urls and store them in my database. However, a recent batch appeared with a ' where the ' was.

Any help is greatly appreciated. Thank you in advance.

Answer

472084 picture 472084 · Oct 19, 2011

Have a go using str_replace(), it's quicker than preg_replace() since it doesn't use regular expressions.

$text = str_replace("'", '', $text);