1

How do I replace the iOS apostrophe ’ with php using preg_replace ?

I tried

preg_replace("/(\u2019)/", '-', $mytring); //Compilation failed: PCRE does not support \L, \l, \N{name}, \U, or \u

preg_replace("/(’)/", '-', $mytring); //Not working

Based on answer, I tried

preg_replace("/(\x{2019})/u", '-', 'it’s'); //it’s

But I'm on Windows, does it matter?

Edit: OK it works now, I had to html_entity_decode it first and I couldn't see it from the dump. Thanks to people who answered.

Eric
  • 9,870
  • 14
  • 66
  • 102

2 Answers2

1

You should be able to do it with this:

$result = preg_replace('/\x{2019}/u',"-", $mytring);

There is a similar question here

L McClean
  • 340
  • 1
  • 8
1

You can catch Unicode using \x{xx} and use the /u modifier (PCRE_UTF8) when you need a character value length of 4:

preg_replace('/\x{2019}/u', "'", $mytring);
AymDev
  • 6,626
  • 4
  • 29
  • 52