Solved

PHP &Mysql encoding problem

Posted on 2014-01-03
4
25 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 108

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now