我正在尝试使用带有键的数组作为查找表将字符串转换为数字。
这是数组:
$q2_10_lt = array("Full-time worker" => 1
, "Part-time worker" => 2
, "Unemployed, would like to work" => 3
, "Unable to work (chronically ill/mentally handicapped/physically handicapped)" => 4
, "Pensioner/retired" => 5
, "Housewife/husband" => 6
, "Student at university of college (post-matric)" => 7
, "High school learner" => 8
, "Primary school learner" => 9
, "Child attending pre-school/nursery school/crèche/day-mother" => 10
, "Child staying at home" => 11
, "Other" => 12);
有问题的关键是“上学前班/托儿所/托儿所/日间母亲的孩子”。使用以下代码时找不到此键:
$person_tempArr[] = $q2_10_lt[$row["q2_10"]] != null ? $q2_10_lt[$row["q2_10"]] : "12";
$person_tempArr[] = $q2_10_lt[$row["q2_10"]] == null ? $row["q2_10"] : "";
该$row["q2_10"]
值只是从 MySQL DB 中获取的不同字符串。
我应该从第一行得到数字 10,但我得到的是 12,并且完整的字符串没有改变“孩子就读学前班/托儿所/托儿所/日间母亲”。
这一定与特殊字符è有关,但我一直无法解决。请提供任何帮助。
编辑 1
按照建议进行十六进制转储后,我得到以下结果
从 SQL 数据库:
43 68 69 6c 64 20 61 74 74 65 6e 64 69 6e 67 20 70 72 65 2d 73 63 68 6f 6f 6c 2f 6e 75 72 73 65 72 79 20 73 63 68 6f 6f 6c 2f 63 72 e8 63 68 65 2f 64 61 79 2d 6d 6f 74 68 65 72
从 php 中的字符串:
43 68 69 6c 64 20 61 74 74 65 6e 64 69 6e 67 20 70 72 65 2d 73 63 68 6f 6f 6c 2f 6e 75 72 73 65 72 79 20 73 63 68 6f 6f 6c 2f 63 72 c3 a8 63 68 65 2f 64 61 79 2d 6d 6f 74 68 65 72
The difference was "E8" vs "C3A8" or "è" from the DB vs "è" from the php string.
So how can I go about ensuring the php string remains "è"?