- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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);
Advertisements