Home > Backend Development > PHP Tutorial > Make PHP's pathinfo() function return the correct filename if the filename is UTF-8 encoded

Make PHP's pathinfo() function return the correct filename if the filename is UTF-8 encoded

WBOY
Release: 2023-09-09 15:34:02
forward
1388 people have browsed it

Make PHPs pathinfo() function return the correct filename if the filename is UTF-8 encoded

Most core PHP functions do not handle character sets other than Latin-1. But before "pathinfo", placing "setlocale" can be used to return the correct filename, even if it is UTF-8 encoded.

By default it runs using the "C" locale and CLI scripts run using the default utf-8 locale. Before calling other functions, the locale on the server should be changed from "C" to "C.UTF-8" or "en_US.UTF-8".

setlocale(LC_ALL,'en_US.UTF-8');
pathinfo($OriginalName, PATHINFO_FILENAME);
pathinfo($OriginalName, PATHINFO_BASENAME);
Copy after login

The above is the detailed content of Make PHP's pathinfo() function return the correct filename if the filename is UTF-8 encoded. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template