To convert a string to slug in PHP you can use the following snippet.
Sample PHP
function StringToSlug($input, $replacement){ (!isset($replacement) || trim($replacement)===''){ $replacement = "/" } $input = strtolower(trim($input)); $input = preg_replace('/[^a-z0-9-]/', $replacement, $input); $input = preg_replace('/-+/', $replacement, $input); return $input; }