1

I have plain Japanese hieroglyphs texts with utf8mb_general_ci in MySQL table, I can fetch row and display as a single string. But what I need is to get a single character from string and use it for a query to match other results(find other hieroglyphs words that consist of that specific single hieroglyph). Problem is that when I loop that string, all I get is ? marks. I read that I have to use UTF8 everywhere but I believe I do.

So, what are the steps from zero to make sure so I can fetch Japanese hieroglyph string, split into separate chars and queries would understand what kind of input is that(not just a ? mark).

Here's some basic code below as an example with the same data that I fetch from my DB and which results in the same problem.

    <html>
        <head>
            <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        </head>
        <body>
            <?php
        $word = "東京のビルの中";
        echo $word;
        echo strlen($word);
        echo "<br>";
        $chars = str_split($word);
        foreach($chars as $single) {
            echo $single . "<br>";
        }
            ?>
        </body>
    </html>
av3000
  • 73
  • 5
  • 1
    You need to use PHP Multibyte String Functions for this -> more info here https://www.php.net/manual/en/ref.mbstring.php – Bart Jul 30 '19 at 22:42

1 Answers1

1

This answer works fine in your case as well. Just add the function to your code and then just call

$chars = mb_str_split($word);
YTZ
  • 876
  • 11
  • 26