Skip to content

Instantly share code, notes, and snippets.

@AlexMcowkin
Created June 23, 2015 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexMcowkin/057593d7301a11d498a8 to your computer and use it in GitHub Desktop.
Save AlexMcowkin/057593d7301a11d498a8 to your computer and use it in GitHub Desktop.
php: обрезка заголовка по целым словам!
<?php
function cut_title($string)
{
$desired_width = 70;
$string = substr($string, 0, $desired_width+1);
if (strlen($string) > $desired_width)
{
$string = wordwrap($string, $desired_width);
$i = strpos($string, "\n");
if ($i) {
$string = substr($string, 0, $i);
}
}
return ucwords(strtolower($string));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment