av3000
av3000

Reputation: 73

Displaying japanese characters with PHP

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>

Upvotes: 1

Views: 1351

Answers (1)

YTZ
YTZ

Reputation: 938

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);

Upvotes: 1

Related Questions