Skip to content

Instantly share code, notes, and snippets.

@sdfsdhgjkbmnmxc
Created March 28, 2018 15:43
Show Gist options
  • Save sdfsdhgjkbmnmxc/0b7106efc96b582987ffd75bf906f7e4 to your computer and use it in GitHub Desktop.
Save sdfsdhgjkbmnmxc/0b7106efc96b582987ffd75bf906f7e4 to your computer and use it in GitHub Desktop.
function clean_title($s, $max_chars=64) {
$result = '';
$arr = str_split($s);
$allowed_chars = str_split('0123456789"(),.:;- йцукенгшщзхъфывапролджэёячсмитьбюqwertyuiopasdfghjklzxcvbnm');
foreach ($arr as $char) {
if (len($result) >= $max_chars) {
break;
}
if (in_array(strtolower($char), $allowed_chars)) {
$result += $char;
}
}
return $result;
}
@dimaninc
Copy link

function cleanTitle($s, $maxChars = 64) {
	$regex = '#[^"()\x20,.:;-а-яa-z0-9]#';
	return substr(preg_replace($regex, '', mb_strtolower($s)), 0, $maxChars);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment