I'm grabbing chinese characters from .csv file and echoing out into HTML through PHP, having great difficulties grabbing them directly from .csv I copy-pasted into .txt and became easier to deal with the data, my hanzi_characters.txt have several hundreds of lines line this example:
hanzi_characters.txt
产品
產品
囚徒困境
不正当竞争
What I need and I cannot figure out how to do properly, is to show one hanzi in each line, like this:
产
品
產
品
I tried using foreach loops with str_split() and explode() as is considered a string, but only outputs ������.
Before running out of ideas I also tried with array_chunk() and array_slice() but as expected the result was the same as not using those methods.
I also tried this solution assigning $s = parts[0];
but couldn't make it work neither
Right now this is my code:
Index.php
<?php
$myfile = fopen("hanzi_characters.txt", "r") or die("Unable to open file!");
while (!feof($myfile)) {
$printed = fgets($myfile);
$parts = preg_split('/[\\s,]/u', $printed);
$echo parts[0];
}
fclose($myfile);
?>
Current output:
产品
產品
囚徒困境
不正当竞争