Skip to content

Instantly share code, notes, and snippets.

@AlexPashley
Last active December 18, 2015 23:19
Show Gist options
  • Save AlexPashley/5861087 to your computer and use it in GitHub Desktop.
Save AlexPashley/5861087 to your computer and use it in GitHub Desktop.
PHP: Dynamic slug function with SEO improvements
<?php
/**
* Used to give the full hyperlink for dynamic items
*
* @param $type string - events/news
* @param $id int - ID of item for link
* @param $title string - item title for link to strip bad chars
**/
function seo_slug ( $type, $id, $title )
{
// strip bad chars
$slug = trim(strtolower(preg_replace("/[^a-zA-Z0-9\s]/", "", $title)));
$slug = str_replace(' ','-', $slug);
$slug = str_replace(' ','-', $slug);
return '/'.$type.'/'.$id.'/'.$slug.'/';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment