Strange character in RecursiveIteratorIterator

Hello, I have a problem while I list the files in a folder named upload, When There arabic file. He shows

           $target = "upload";
    $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($target));

    while($it->valid()) {

        if (!$it->isDot()) {
            $nom=$nom+1;
            echo $it->getSubPathName();
            echo '<tr align="center"><td> <a href="play.php?fil=' . $it->getSubPathName() . '">Play</a> </td><td>' . $it->getSubPathName() . '</td><td>' . $nom . '</td></tr>'; } }
+4
source share
1 answer

First, convert the text to UTF-8:

iconv('CP1256', 'UTF-8', $it->getSubPathName());

Then, make sure the web browser decodes the page correctly as UTF-8. Put this as the top of your PHP file:

<?php
header("Content-Type: text/html; charset=UTF-8");

// The rest of the code
+2
source

Source: https://habr.com/ru/post/1530251/


All Articles