Solved

PHP &Mysql encoding problem

Posted on 2014-01-03
4
29 Views
Last Modified: 2016-05-17
I am selecting Arabic and English file names from mysql database...

But the php function is_file() don't recognize the file name, although it can see the English files.

I tried to detect the selected name encoding, found (UTF-8)

$q = mysql_query("select `file` from `my_table` ");

while( $data = mysql_fetch_assoc($q) ){
    
    $file_path = "path_to_file".$data['file'];

    if (is_file ($file_path)){
    
       echo $data['file']." found<br/>";
  
    }

}

Open in new window

0
Comment
Question by:darroosh
4 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39753257
0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39753888
Couple of thoughts... PHP was built on the assumption that a character == a byte.  Perhaps this made sense in a 1990's sort of way in western languages, where all 256 characters could be represented by 8 bits (ISO-8859-1), but it ignored most of the world where there can be, literally, thousands of characters needed to communicate meaning.  Palpably something was amiss.

Enter UTF-8 encoding.  Now you can have from one to four bytes in each character.  Below code point 128 the ASCII characters match, so ISO-8859-1 and UTF-8 look the same there.  Above code point 128, UTF-8 characters are multi-byte.  This article explains the details and shows the symptoms of character set collisions.

PHP's assumptions about character sets are changing at Release 5.4, so you may be in for some surprises as you upgrade.  However, the server file system probably still has the 1:1 ratio of byte:character.  I recommend that you use only ASCII characters in file names.  This will guarantee that your names will be in consonance with the 1:1 ratio that prevents collisions between UTF-8 and ASCII.  The recommendation only extends to the file names, not the contents of the files or the SQL tables.  The internal encoding of the data can be UTF-8, no matter what characters are used to name the files.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Moving from Mcrypt to OpenSSL 18 48
XML extra information 8 30
How to set the Tinymce Editor image path 4 23
Use Select Query to Return Results as a Form 9 25
These days socially coordinated efforts have turned into a critical requirement for enterprises.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question