Stijn Hoste
Stijn Hoste

Reputation: 874

Removing a single quote out of a string in PHP

I'm trying to remove the ' out of my string.

Here's my code:

$page_title = strtolower(wp_title( '', false, 'right' ));
echo $page_title;
echo "<br/>";
$clean = preg_replace('/[^A-Za-z0-9\-]/', '', $page_title);
echo $clean;

Output:

regio’s 
regio8217s

Why does it return 8217 instead of ''?

Thanks in advance

Upvotes: 0

Views: 485

Answers (2)

Nate from Kalamazoo
Nate from Kalamazoo

Reputation: 436

Try preg_replace('/[^A-Za-z0-9\-]/u', '', $page_title);

the u after the pattern processes unicode characters too.

Upvotes: 0

Hobo
Hobo

Reputation: 7611

Your quote has been converted to its unicode value (&#8217;) (see here for example). It's a special character, not a standard one.

Upvotes: 1

Related Questions