Trying to make a url generator from a title |
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
Try using the url_title from the url helper: https://www.codeigniter.com/user_guide/h...#url_title
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
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; } |
Welcome Guest, Not a member yet? Register Sign In |