To overcome this issues, i've created a new php code to assist my work. This is very basic code based on Regex pattern to remove all non alphanumeric character and change all spaces into dashes.
Here is what i want for this code:
1. Remove non alphanumeric chars.
2. Change spaces into dashes.
3. All must lowercase.
To fulfill above rule here the simplest code:
function slugify($txt) { // replace all non alphanumeric into dashes $text = preg_replace('/\W+/', '-', $txt); // trim and lowercase return strtolower(trim($txt, '-')); } ?>
Example scenario:
Mistery of Mine & How to : Extracting IP Values IPv6 2012 under 10% value
Will converted into:
mistery-of-mine-how-to-extracting-ip-values-ipv6-2012-under-10-value
Hope it help others.
No comments:
Post a Comment