特殊字符无处不在,但在控制器 codeigniter 中不起作用
Special characters are working everywhere but not in the controller codeigniter
我有一个 restaurant.The 所有者的数据库将添加比萨饼、沙漠或意大利调味饭等类别(无重音符号或特殊字符)或具有特殊 characters/accents 的类别,例如 Salată、Peşte 或 Vodkă(罗马尼亚字符)。
类别的 table 设置为接受特殊 characters.I 用于 ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8
。
在导航栏中,我有一个包含所有产品(食品和酒吧)的下拉菜单。
要访问一个类别,我正在使用 GET
,如下所示:
<?php foreach ($categories_bar as $category): ?>
<a class="dropdown-item" href="<?php echo site_url('/bar/'.implode('_',explode(" ",$category['category_name']))); ?>"><?php echo $category['category_name']; ?></a>
<?php endforeach; ?>
如果类别名称只包含一个单词,则 URL
将是 http://localhost/quartiere/bar/name_of_the_category if the category name will have 2 or more words or http://localhost/quartiere/bar/nameofthecategory。
当用户点击某个类别时,服务器将执行以下操作:
- 使用类别名称获取类别的 ID(来自 url)
- 获取具有特定类别 ID 的产品
- 在页面上显示它们。
问题是,当单击带有特殊字符的类别时,数据库不会显示正常名称...它会显示如下内容(对于单词 Pălincă)-> P%C4%83linc% C4%83.
很奇怪,因为在下拉列表中名称显示正确。
应该显示每个类别的产品的函数是 this.At 开始我正在反转我在 navbar.Doing 中正在做的 explode-implde 过程,我将有一个字符串就像数据库中的字符串:
public function bar_view($name = NULL){
$name_to_pass = implode(' ',explode('_',$name));
$category = $this->products_model->get_category_id($name_to_pass);
$products = $this->products_model->get_bar_prods_by_category($category);
$data['title'] = $name_to_pass;
$data['products'] = $products;
if(empty($data['products'])){
show_404();
}
$this->load->view('templates/header');
$this->load->view('menu/bar_view',$data);
$this->load->view('templates/footer');
}
要指定:
- 在
head
我有 <meta charset="utf-8">
- 在配置文件中我有这个
$config['charset'] = 'utf-8';
- 在数据库文件中我有这个
'char_set' => 'utf8'
和 'dbcollat' => 'utf8_general_ci'
听起来您只需要:
urldecode()
Decodes any %## encoding in the given string. Plus symbols ('+') are
decoded to a space character.
$name_to_pass = implode(' ',explode('_', urldecode($name)));
我有一个 restaurant.The 所有者的数据库将添加比萨饼、沙漠或意大利调味饭等类别(无重音符号或特殊字符)或具有特殊 characters/accents 的类别,例如 Salată、Peşte 或 Vodkă(罗马尼亚字符)。
类别的 table 设置为接受特殊 characters.I 用于 ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8
。
在导航栏中,我有一个包含所有产品(食品和酒吧)的下拉菜单。
要访问一个类别,我正在使用 GET
,如下所示:
<?php foreach ($categories_bar as $category): ?>
<a class="dropdown-item" href="<?php echo site_url('/bar/'.implode('_',explode(" ",$category['category_name']))); ?>"><?php echo $category['category_name']; ?></a>
<?php endforeach; ?>
如果类别名称只包含一个单词,则 URL
将是 http://localhost/quartiere/bar/name_of_the_category if the category name will have 2 or more words or http://localhost/quartiere/bar/nameofthecategory。
当用户点击某个类别时,服务器将执行以下操作:
- 使用类别名称获取类别的 ID(来自 url)
- 获取具有特定类别 ID 的产品
- 在页面上显示它们。
问题是,当单击带有特殊字符的类别时,数据库不会显示正常名称...它会显示如下内容(对于单词 Pălincă)-> P%C4%83linc% C4%83.
很奇怪,因为在下拉列表中名称显示正确。
应该显示每个类别的产品的函数是 this.At 开始我正在反转我在 navbar.Doing 中正在做的 explode-implde 过程,我将有一个字符串就像数据库中的字符串:
public function bar_view($name = NULL){
$name_to_pass = implode(' ',explode('_',$name));
$category = $this->products_model->get_category_id($name_to_pass);
$products = $this->products_model->get_bar_prods_by_category($category);
$data['title'] = $name_to_pass;
$data['products'] = $products;
if(empty($data['products'])){
show_404();
}
$this->load->view('templates/header');
$this->load->view('menu/bar_view',$data);
$this->load->view('templates/footer');
}
要指定:
- 在
head
我有<meta charset="utf-8">
- 在配置文件中我有这个
$config['charset'] = 'utf-8';
- 在数据库文件中我有这个
'char_set' => 'utf8'
和'dbcollat' => 'utf8_general_ci'
听起来您只需要:
urldecode()
Decodes any %## encoding in the given string. Plus symbols ('+') are decoded to a space character.
$name_to_pass = implode(' ',explode('_', urldecode($name)));