Strings Max Lenght Control function for Drupal

Objective:
Create one function that controls the length for one string of caharacters in drupal.

Function:

<?php
function max_length($string) {
$string = check_plain($string);
$length = 25;//string max length value
if (drupal_strlen($string) > $length) {
   
$output  = substr($string,0,$length) .'...';
}
else {
   
$output  = $tstring;
}
return
$output;
}
?>

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><h2><h3><div><del><img><hr>
  • Lines and paragraphs break automatically.
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
8 + 4 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.