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 7521927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:22:17+00:00 2026-05-30T02:22:17+00:00

I just learned about character sets today, so forgive the newb factor if this

  • 0

I just learned about character sets today, so forgive the newb factor if this is confusing. Please ask for clarification if it’s needed.

I wrote a program in php which recursively goes through the files in a folder and stores the file names in a database. The file names are then all exported from the database in json format using the json_encode($array) function.

However this function only works with UTF-8 encoded data. And since a few of the key-value pairs in the json export have the value of null, I’m lead to believe that those strings of filenames taken from the database are in fact not utf-8.

I’ve ensured that all the data going in and out of the the database is utf-8 by setting the defaults to utf-8 in my.cnf and restarting mysql from the command line using service mysql restart

[client]
default-character-set=utf8

[mysqld]
default-character-set = utf8

I then created my database, the table and all the columns in the table and confirmed that the database, table and all the columns are in fact utf-8

Checks if database is utf-8

SELECT default_character_set_name FROM information_schema.SCHEMATA S
WHERE schema_name = "schemaname";

Checks if table is utf-8

SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,
       information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
WHERE CCSA.collation_name = T.table_collation
  AND T.table_schema = "schemaname"
  AND T.table_name = "tablename";

Checks if field is utf-8

SELECT character_set_name FROM information_schema.`COLUMNS` C
WHERE table_schema = "schemaname"
  AND table_name = "tablename"
  AND column_name = "columnname";

There’s this file that has the characters –µ–ª–∫—É–Ω—á–∏–∫ in the file name. When it’s stored in the database the values appear as –©–µ–ª–â’.

Per my database settings, are all the strings going in and out of my database utf-8?

What can I do to ensure the data I am SELECT’ing from the database is utf-8, so I can perform json_encode($array)? (NOTE: this function only works on utf-8 encoded data)

  • 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-05-30T02:22:18+00:00Added an answer on May 30, 2026 at 2:22 am

    Unfortunately I don’t know how you can ensure everything coming out is UTF-8 (now I’m curious too!), but a starting point would be trying this in your PHP:

    $encodedNames = array();
    $errors = array();
    
    // Loop through all of the filenames
    foreach($filenames as $filename)
    {
      // Check if it's UTF-8 encoded
      if('UTF-8' === mb_detect_encoding($filename, 'UTF-8', true))
      {
        $encodedNames[] = $filename;
      }
      else
      {
        $errors[] = $filename;
      }
    }
    
    // json_encode the UTF-8 filenames
    $jsonString = json_encode($encodedNames);
    
    // Log the other filenames here so you can deal with them later...
    

    http://php.net/manual/en/function.mb-detect-encoding.php

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

Sidebar

Related Questions

I just posted this question and learned about <see cref=> , however when i
I just learned about XLST on stackoverflow today (I love how in computers you
I just learned about .delegate today, and I know I can be used for
I just learned about the Template Method pattern in this answer to a question
I just learned about this fine looking syntax Collections.<String>emptyList() to get an empty List
I just learned about how the Java Collections Framework implements data structures in linked
I just learned about ngrep , a cool program that lets you easily sniff
I just learned about how to include FxCop on a build. But it's slow
I've got an application that just shipped. Since I wrote it, I've learned about
I just learned about list comprehension, which is a great fast way to get

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.