Solved

PHP &Mysql encoding problem

Posted on 2014-01-03
4
33 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39753257
0
 
LVL 110

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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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.

751 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