How to display Tamil content form mysql database i

2019-08-20 07:24发布

问题:

I am having problem for viewing the Tamil content which retrive from mysql database using CodeIgniter. but the same code is working in core php. i have attached my code below. please check my code and give answer if any changes.

this is my view code:

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

    <table class="table table-striped table-bordered table-hover dataTables-example" >
                <thead>
                <tr>
                    <th>Title</th>
                    <th>Description</th>
                 </tr>
                </thead>
                 <tbody>
                          <?php

                               foreach ($per_results as $result)
                               {

                               ?>
    <tr class="">

                               <td><?php echo $result->title;?></td>
                               <td><?php echo $result->description;?></td>
   </tr>
    <?php
                               }
                               ?>

                          </tbody>

                </table>

This is my Controller COde:

   public function view_mainhome()
    {
      $data['per_results'] = $this->Login_model->getview_permission();
      $this->load->view('forest_add/view_mainhome',$data);
    }   

This is my Model Code:

        function getview_permission() //Stock
        {   
        $this->db->select('*');
        $this->db->from('forest_permission');
        $this->db->order_by("per_id", "asc");
        $query = $this->db->get();
         return $query->result();
        }

Thanks @

回答1:

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

Please try this code in your document header. I hope this will work for Tamil language.



回答2:

As per my comment,

Change datatype of SQL column to utf8_general_ci



回答3:

@user3839366 utf8_general_ci is the collation, make sure you have the same collation for other table fields which you join and compare.

I'm leaving this for anyone else having the utf8 issues. If you have unicode characters, you can do this while creating the table,

CREATE TABLE `your_table_name` (
....
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

or later

ALTER TABLE `your_table_name` CONVERT TO CHARACTER SET utf8;

with specific collation

CREATE TABLE `your_table_name` (
....
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_general_ci;

or later

ALTER TABLE `your_table_name` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;

note:- You can use utf8mb4 if you want full unicode support (eg, store an emoji in your db)

Also if you want to see the result in console, run set names utf8; (also for programs or scripts that do not have out of the box unicode support)