简体   繁体   中英

Codeigniter: How to pass UTF8 parameters to a controller using url?

I'm using Code-igniter 3 and need to pass a parameter to a controller using URL parameters. My URL is something like this:

http://192.168.40.50/user/list/محمد

And I added this to the config file :

$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-|آ-ی';

And my controller is like this:

public function list($name)
{ 
    // The $name parameter is incorrect here
    // In this case $name = 'E-E'
}

The problem is that I'm getting 'EE' instead of 'محمد'.

I just search a lot of questions but didn't find a solution

َUPDATE

I'm using routing. The parameters are delivered correctly without routing but when I add routes UTF-8 characters are changed. My route is just like this:

$route['user/list/(:any)'] = 'user/list_of/$1';

Phil Sturgeon explains allowing UTF-8 extensively: here is an excerpt followed by the full article link:

Set the HTTP header in index.php All requests to CodeIgniter are made through the index.php file which by default sits outside the system/ folder. For this reason it makes a perfect place to add a PHP header for me.

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

Tell CodeIgniter what's going on CodeIgniter by default is set to use UTF-8 for much of its internal functionality, so just make sure the charset is set to UTF-8 in your application/config/config.php file.

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

Configure database connection

$db['default']['char_set'] = "utf8"; $db['default']['dbcollat'] = "utf8_unicode_ci";

At this point you should be able to use the UTF-8 Characters, if you want to save it into the DB which I am using you would do, read on further using this link:

USING UTF-8

You can also refer to this stackoverflow post: Using UTF-8 Stackoverflow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM