Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PHP &Mysql encoding problem

Posted on 2014-01-03
4
Medium Priority
?
37 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 84

Expert Comment

by:Dave Baldwin
ID: 39753257
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

704 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