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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2023-09-09 15:33:091466browse

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete