PHP : Array key containing special character not found

前端 未结 2 1945
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-22 11:19

I am trying to convert strings to numbers using an array with keys as a lookup table.

This is the array:

$q2_10_lt = array(\"Full-time worker\" => 1
          


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-22 11:57

    I ended up changing my table column encoding to utf8_general_ci and table collation to utf8_general_ci. I also added the following lines of code to my php file:

    ini_set('default_charset', 'utf-8');
    
    //set encodig to utf-8
    mysql_query("SET NAMES 'utf8'"); 
    mysql_query("SET CHARACTER SET 'utf8'");
    

    It is working now, but I could be doing something not recommended?

提交回复
热议问题