Skip to content

Instantly share code, notes, and snippets.

@sdeluce
Last active January 4, 2016 01:29
Show Gist options
  • Select an option

  • Save sdeluce/8548383 to your computer and use it in GitHub Desktop.

Select an option

Save sdeluce/8548383 to your computer and use it in GitHub Desktop.
Creer un texte d'intro d'un paragraphe.
<?php
function truncate($string, $max_length = 50, $replacement = '...', $trunc_at_space = false) {
$max_length -= strlen($replacement);
$string_length = strlen($string);
if($string_length <= $max_length)
return $string;
if( $trunc_at_space && ($space_position = strrpos($string, ' ', $max_length-$string_length)) )
$max_length = $space_position;
return substr_replace($string, $replacement, $max_length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment