T
T
TopClans2017-12-08 10:48:02
css
TopClans, 2017-12-08 10:48:02

PHP: Why is the encoding of a single character of a string different from the encoding of the string itself?

There is an archive, it contains files with names in Russian.
Using ZipArchive, I open the archive, and I want to unpack only those files whose name begins with the letter U, in Russian.
It didn’t work right away, it turned out that ZipArchive works in CP866, so I did this:

$filename = $zip->getNameIndex($i);
$filename = iconv('CP866', 'utf-8', $filename);
echo $filename;

As a result, I get the correct file name.
Then I check for the first character ( $filename[0] or substr($filename, 0, 1) ) - it doesn't work. I did the output of this character - I got this: "First character of the file: �"
I tried to set the script encoding at the very beginning:
mb_internal_encoding("utf-8");
But this did not help either.
I tried to compare the entire line with the full file name - it works, it converges:
if ($filename == "uf100000.xls") echo "Yes";
This is my first time, what could be wrong?
answer: it was necessary to take the first 2 characters: substr($filename, 0, 2) , or use another function:mb_substr($filename, 0, 1)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman, 2019-09-25
@Nohaga

No one has made such buttons as pictures for a long time, they use css for this.
This can be done manually, or you can use online constructors like this https://www.css3buttongenerator.com/
here is a small example:
Of course, I didn’t pick up the colors, fonts and sizes perfectly, but you can do it yourself
PS: corrected the shadow

A
Alexey Hog, 2017-12-08
@TopClans

- got this: "First character of the file: �"

Instead of substr use mb_substr or any other functions Functions for working with Multibyte strings

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question