I am making a simple blog in CodeIgiter framework. I can create posts and when a post is created the slug is saved in the database. The slug is the same as the title of the post but what if the post is in a special charecter? For example the title of the post is "Ķas-noķika" and when I press read more a link shows me the slug like this - http://localhost/CodeIgniteBlog/posts/Ķas-noķika
. In the database the slug is the same as in the link but it does not fetch the post instead it shows me the 404 message. So I am thinking of converting the url slug from Ķas-noķika
to Kas-nokika
in hopes that it would work. How do I do such a thing in CodeIgniter? Do I have to change config.php or add a function?
here is the function that creates the post:
public function create_post(){
$slug = url_title($this->input->post('title'));
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'body' => $this->input->post('body')
);
return $this->db->insert('posts', $data);
}
Use convert_accented_characters()
, but first you need to load the "text" helper.
Here's an example:
echo convert_accented_characters("Ķas-noķika"); //Output Kas-nokika
More info can be founded on the documentation link: https://www.codeigniter.com/user_guide/helpers/text_helper.html#convert_accented_characters