Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8749625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:43:29+00:00 2026-06-13T12:43:29+00:00

I am trying to convert strings to numbers using an array with keys as

  • 0

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
                , "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);

The problematic key is “Child attending pre-school/nursery school/crèche/day-mother”. This key is not found when using the following code:

$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"] : "";

The $row["q2_10"] value is just the different strings taken from MySQL DB.

I should get the number 10 from the first line, but instead I get 12 and the complete string unaltered “Child attending pre-school/nursery school/crèche/day-mother”.

This must have something to do with the special character è, but I have not been able to solve it. Any help please.

EDIT 1

After doing a hex dump as suggested, I got the following results

From SQL DB:

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

From string in 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 “è”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:43:30+00:00Added an answer on June 13, 2026 at 12:43 pm

    The string you get from your database layer is not the same string you use as the key. To fix it, use the same string each time.

    Same means here, that the string is the same byte-by-byte. Do a hexdump of the string you get from the database.

    Then enter the binary string as key (or at least for the special letter). This will make your code more robust because it will work regardless in which encoding you’re saving the PHP file.

    Edit: As you compare against the database, the key needs to co-related to the binary sequence in the database:

            , "Child attending pre-school/nursery school/cr\xE8che/day-mother" => 10
                                                           ^^^^
    

    Use the hexadecimal notation to express the bytes you are not able to “type” with your UTF-8 encoded PHP file. The database uses some ISO-8859-1 or similar encoding.

    As you can see it is just \x and then the hexcode E8. It works in double-quoted strings in PHP.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code for on android just trying to convert string to
I'm trying to convert a floating point to byte array/stream using javascript. My javascript
I need to convert strings with optional trailing signs into actual numbers using Powershell.
i'm trying to convert numbers into localized strings. For integers and money values it's
I'm trying to convert packed decimal numbers into ascii strings. Here is my understanding
I'm trying to retrieve odd values in a List of strings and convert them
I'm trying to convert string using Var encode:ansistring; begin encode:=UTF8Encode('اختبار'); showmessage(encode); end; It's working
I'm trying to convert a string to an array of integers so I could
I'm trying to convert a String to a byte array which has 2 different
I'm trying to convert a 128-bit unsigned integer stored as an array of 4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.