1

I am trying to set up PHP's Transliterator class, to convert some strings which have characters in the range of utf-8, to simple [a-z] characters, but I am having trouble in figuring out how to use it.

I have set up my code exactly like this answer https://stackoverflow.com/a/13019489/2691879 yet the echoes return only empty strings.

(Here's the code part from that answer, if you don't want to click the link:)

$str1 = 'Orléans'
$str2 = 'Angoulême'
$rule = 'NFD; [:Nonspacing Mark:] Remove; NFC';

$transliter = Transliterator::create($rule); 
echo $transliter->transliterate($str1);
echo $transliter->transliterate($str2);

I googled for like an hour now, but can't find how to correctly set up the rules, neither anyone with a simmilar problem to mine.

If I replace the special characters from the two strings, with [a-z] representation, the transliterator echoes them out.

Why are the two echo statements returning an empty string? How could I achieve my desired result?

Community
  • 1
  • 1
Adam Baranyai
  • 3,635
  • 3
  • 29
  • 68
  • Let's start from the top, do you have the [intl (Internationalization) extension](http://www.php.net/manual/en/intro.intl.php) installed in PHP? In your code you declared two variables without adding semicolons to the end of them, you'll need to fix that for it to work. Additionally turn on error reporting within your script by adding `error_reporting(-1);`to the top of it. – C.Liddell Apr 04 '16 at 12:02
  • So, the above code was a copy from the answer, I've already added the semicolons in my code, I have the intl extension installed, the Transliterator object is created properly, if I try to get the latest error message from Transliterator, this is what I got: **String conversion of string to UTF-16 failed: U_INVALID_CHAR_FOUND** – Adam Baranyai Apr 04 '16 at 12:13
  • What version of PHP are you running? This works fine for me on version 7.0.2. The [requirements page](http://php.net/manual/en/intl.requirements.php) on PHP's website states you need at least PHP version 5.2.0 and version 4.0.0 of the ICU library. – C.Liddell Apr 04 '16 at 12:34
  • What Operating System are you running? If OS X or Linux tell me the output of the following command: `uconv -V` – C.Liddell Apr 04 '16 at 12:50

0 Answers0