• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to make a url generator from a title

#1
Hi there,

I have been trying to make a generator that will take a title and strip out all the special characters like !"£$ etc...

I have used strtolower and str_replace in a chain with each character but it is inconsistent and will not strip everything like ~.

Is there anything out there that can help with something like this,  I have had a bit of a search but nothing had turned up yet.

Thanks,

Doomie
Reply

#2
Try using the url_title from the url helper: https://www.codeigniter.com/user_guide/h...#url_title
Reply

#3
Hi,
I don't know which version Codeigniter you are using but if you're using 3.x, you can try URL helper function: url_title. You can reach the references with the link below.

https://www.codeigniter.com/user_guide/h...#url_title

Hope this helps
Reply

#4
First of all we need to strip all special characters and punctuation away. 
This is easily accomplished with something like:

function toAscii($str) {
$clean = preg_replace("/[^a-zA-Z0-9/_|+ -]/", '', $str);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[/_|+ -]+/", '-', $clean);

return $clean;
}

Second option
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str) {
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
$clean = preg_replace("/[^a-zA-Z0-9/_| -]/", '', $clean);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[/_| -]+/", '-', $clean);

return $clean;
}
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.