开发者

UTF8 Char in Codeigniter

开发者 https://www.devze.com 2023-03-29 21:08 出处:网络
i have a problem. I hope you can help me. I don’t speak english very well, but i try to explain me good as i can.

i have a problem. I hope you can help me. I don’t speak english very well, but i try to explain me good as i can.

I am from argentina, so, i have to work with the “ñ” character. For SEO, i want include the “ñ” at the url for some words, so, for example, i have:

  • Controller: webdesign.php
  • Route: $route[‘diseñoweb’] = “webdesign”;

But, when i enter to “www.do开发者_如何学JAVAmain.com/diseñoweb” it doesn’t work. And i need the “ñ” character in the url. Do somebody know how can i do this?

Thank you!


What you want to do is most likely not going to work as you want, because URLs can't contain non-ASCII characters. See here for background.

I think you need to create a route for the URLencoded version, like so:

$route['dise%c3%b1oweb'] = "webdesign";

if you then enter a URL containing

diseñoweb

a modern browser will automatically URLencode the character.


first, you need to allow that char in your config, for example you can have something like these…

$config['permitted_uri_chars'] = 'a-z 0-9_\-ñ'; 

Then, at system/core/URI.php, on line 231, replace

if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", $str)) 

to

if ( ! preg_match("|^[".str_replace(array('\\-', '\-'), '-', preg_quote($this->config->item('permitted_uri_chars'), '-'))."]+$|i", utf8_encode($str))) 


You may try this

$route[rawurlencode('diseñoweb')] = “webdesign”;
0

精彩评论

暂无评论...
验证码 换一张
取 消