- array_map: documentation ( source)
- var_dump: documentation ( source)
- str_replace: documentation ( source)
- trim: documentation ( source)
- preg_replace: documentation ( source)
- strtolower: documentation ( source)
<?php
function tagify($text, $spacer = '-')
{
//Handle if array
if (is_array($text)) {
return array_map("tagify", $text);
}
$text = str_replace('&', 'and', $text);
return str_replace(' ', $spacer, trim(preg_replace('#([^a-z0-9/]+)#', ' ', strtolower($text))));
}
var_dump(tagify(['something else', 'per che']));