Abbbas khan
Abbbas khan

Reputation: 302

best way to handle url in codeigniter even special characters

in codeigniter i want to write url for my project base on product title fetch by google bing and amazon by API.

i don't know how to handle and what type of url is best

if title url have special character and any type of critical url Whatever.

i have some idea for write url i don't know best way or not .

first when we add record in database those time we add title according url sporting replace special characters and any other types in future create trouble by using str_replace preg_repalce and any other ways.

second those time when we write url we handle it by using str_replace preg_repalce

third we handle in this way $config['permitted_uri_chars'] = 'a-z 0-9~%.:_()@\-';

if any one have more ideas and best way to handle critical url please share experience

Upvotes: 0

Views: 194

Answers (1)

PaulD
PaulD

Reputation: 1171

Codeigniter comes with a very handy URL helper. One of the functions is for doing just that. (Removes any illegal characters, replaces spaces and can force lowercase which I always use).

$title = "This is my best product";

$url_title = url_title($title, '-', TRUE);

// Produces: this-is-my-best-product

The first argument is your string, the second is the word separator you want to use ( '_', '-', '', etc) and the third argument forces lower case to be used.

You can read about it here: http://www.codeigniter.com/user_guide/helpers/url_helper.html#url_title

Hope that helps,

Paul.

Upvotes: 1

Related Questions