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

  • SEARCH
  • Home
  • 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 6832173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:49:35+00:00 2026-05-26T22:49:35+00:00

I’m using Codeigniter not for so long but I’ve some charset problems.. I’m asking

  • 0

I’m using Codeigniter not for so long but I’ve some charset problems.. I’m asking around at the CI Forum, but I want to go further, still no global solution: http://codeigniter.com/forums/viewthread/204409/

The problem was a database error 1064. I’ve got a solution, use iconv! Works fine, but I think it’s not necessary. I’m searching a lot on the internet for charset’s etc but I’m using CI now, how about charsets and CI…

So I’ve a lot of question about it, I hope someone can make it clear for me:

What’s the best way to set the charset global? And what to set?

  • In the head

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

  • In config/config.php

    $config['charset'] = 'UTF-8';

  • In config/database.php

    $db['default']['char_set'] = 'utf8';

    $db['default']['dbcollat'] = 'utf8_general_ci';

  • In .htaccess, my rewrite rules and

    php_value magic_quotes_gpc Off

    AddDefaultCharset UTF-8

  • Also need send a header? Where to place? Something like?

    header('Content-Type: text/html; charset=UTF-8');

  • In my editor (Notepad++) save files as UTF-8? Or UTF-8 (without BOM)? Or is ANSI good (this is what I’m using now)?

  • Use utf8_unicode_ci or utf8_general_ci for the MySQL database? And why?

  • How about reading RSS feeds, how to handle multiple charsets? Where I’m working on I’ve two feeds, one with UTF-8 encoding and the other with ISO-8859-1. This will be stored in the database and will be compared sometimes to see if there are new items. It fails on special chars.

I’m working with:
– CI 2.0.3
– PHP 5.2.17
– MySQL 5.1.58

More information added:

Model:

function update_favorite($data) 
{
 $this->db->where('id', $data['id']);
 $this->db->where('user_id', $data['user_id']);
 $this->db->update('favorites', $data);
 return;
}

Controller:

$this->favorites_model->update_favorite(array(
 'id' => $id, 
 'rss_last' => $rss_last,
 'user_id' => $this->session->userdata('user_id')
)); 

When $rss_last is a “normal” value like: “test” (without quotes) it works fine.
When it’s a value with more length like (in Dutch): F-Secure vindt malware met certificaat van Maleisische overheid

I get this error:

Error Number: 1064

You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ‘vindt malware met certificaat van Maleisische overheid,
user_id = ‘1’ WHERE `i’ at line 1

UPDATE favorites SET id = ‘15’, rss_last = F-Secure vindt
malware met certificaat van Maleisische overheid, user_id = ‘1’
WHERE id = ‘15’ AND user_id = ‘1’

Filename:
/home/…/domains/….nl/public_html/new/models/favorites_model.php

Line Number: 35

Someone at the CI forum told me to use this:

'rss_last' => iconv("UTF-8", "UTF-8//TRANSLIT", $rss_last) 

This works fine, but I think this is not necessary..

The value $rss_last came out a RSS feed, as told before, sometimes a UTF-8 and other times a ISO-8859-1 encoding:

$rss = file_get_contents('http://www.website.com/rss.xml');
$feed = new SimpleXmlElement($rss);
$rss_last = $feed->channel->item[0]->title;

It looks like this last part is the problem, when $rss_last is set to the value it works fine:

$rss_last = 'F-Secure vindt malware met certificaat van Maleisische overheid';

When the value came out the RSS it give problems…

Some more questions..

Just found this: Detect encoding and make everything UTF-8

Best solution? But.. is iconv not more simple, do something like this:

$encoding = some_function_to_get_encoding_from_feed($feed);
$rss_last = iconv($encoding, "UTF-8//TRANSLIT", $feed->channel->item[0]->title);

But what to use for “some_function_to_get_encoding_from_feed”? mb_detect_encoding?

And mb_convert_encoding vs iconv?

  • 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-26T22:49:36+00:00Added an answer on May 26, 2026 at 10:49 pm

    1) There is no global solution.

    2)

    AddDefaultCharset UTF-8
    

    It’s needed for Apache response to client with right encoding. Make it.

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    

    not necessarily, but recommended by W3C.

    $config['charset'] = 'UTF-8';
    

    it’s desirable

    $db['default']['char_set'] = 'utf8';
    $db['default']['dbcollat'] = 'utf8_general_ci';
    

    Encoding for CI connection to database. If encoding of your database is UTF-8 – make it mandatory.

    header('Content-Type: text/html; charset=UTF-8');
    

    Do not do this unless necessary. Charset already indicated in HTML code and .htaccess.

    Use utf8_unicode_ci or utf8_general_ci for the MySQL database? And why?
    

    For their own language (Russian), I use utf8_general_ci.

    In my editor (Notepad++) save files as UTF-8?
    

    Absolutely! All code that Apache will give as UTF8 should be in UTF8.

    How about reading RSS feeds, how to handle multiple charsets?
    

    If you have each RSS in each table – you can specify charset for each table and set right encoding with each sql query.
    Yes, cyrillic symbols, for example, will fails on non-UTF8.

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I want use html5's new tag to play a wav file (currently only supported
Seemingly simple, but I cannot find anything relevant on the web. What is the

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.