Slug from Title
I have been for years trying to get my head round mod_rewrite and Pretty URLs, and the recent email and Davids example has given me the bug.
I am trying to get my head round 'slugs'. I understand the concept and why we need them, but am trying to figure out how to get DataBridge to do this for me.
I have a Title, Introduction and Content field in a form (as well as date, user etc), and then want the Databridge form to send a slug to the slug column which would be a title with hyphens instead of spaces and special characters removed. I assume that this is generated by the title form field but am not sure how I a) alter the title and b) how I get the form to insert the title in to the title column and the modified version into slug as it will be coming from the same form field.
I have been reading this link which gives me the function;
function create_slug($string){
$string = preg_replace( '/[«»""!?,.!@£$%^&*{};:()]+/', '', $string);
$string = str_replace( "'", '', $string);
$string = strtolower($string);
$slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);
return $slug;
}
$slug = create_slug($title);
But Im not sure where to put this and how to integrate it into an insert form.
Thanks in advance