note 72091 deleted from function.chr by danbrown
| From: | danbrown@php.net | Date: | Wed, 15 Sep 2010 21:09:58 +0000 |
| Subject: | note 72091 deleted from function.chr by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-172591@lists.php.net to get a copy of this message | ||
Note Submitter: Paddy and Ger
----
This is just a small piece that allows you to echo out a set number of characters from a string. We
were writing option values (html form element) dynamically from an xml file. Some of the strings
were too long and as the select tag has no attributes to control the width or columns it seems a
handy way to solve the problem.
$string = "this is some text";
$length = strlen($string); // gets the length of the string
$newLength = -($length - 5); // makes the length smaller by 5 characters
$string = substr("$string", 0, $newLength); // sets the string to be 5 characters in
length
echo $string;