- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Make PHP pathinfo() return the correct filename if the filename is UTF-8
Most of the core PHP functions don’t deal with character sets apart from Latin-1. But before the ‘pathinfo’, placing the ‘setlocale’ can be used to return the correct filename even if it is UTF-8 encoded.
By default, it runs with ‘C’ locale, and CLI scripts run with a default utf-8 locale. The locale on the server should be changed from ‘C’ to ‘C.UTF-8’ or to ‘en_US.UTF-8’ before calling the other functions.
setlocale(LC_ALL,'en_US.UTF-8'); pathinfo($OriginalName, PATHINFO_FILENAME); pathinfo($OriginalName, PATHINFO_BASENAME);
- Related Articles
- C++ Program to count operations to make filename valid
- Get an Absolute Filename Path from a Relative Filename Path in Java
- What is the difference between #include and #include “filename”?
- Get an Absolute Filename Path from a Relative Filename with Path in Java
- Determine if two filename paths refer to the same File in Java
- Unix filename pattern matching in Python
- Unix filename pattern matching in Python (fnmatch)
- Get filename from string path in JavaScript?
- pathinfo() function in PHP
- Convert ASCII TO UTF-8 Encoding in PHP?
- Difference between #include and #include "filename" in C/C++?
- Java Program to strip a filename of its extension after the last dot
- How to list one filename per output line in Linux?
- How to get the last dirname/filename in a file path argument in Bash?
- PHP 8 – How to use ValueError to check if the value encountered is of correct type?

Advertisements