note 110370 added to function.substr
| From: | Nico-at-www.nokes.de | Date: | Tue, 16 Oct 2012 08:57:52 +0000 |
| Subject: | note 110370 added to function.substr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-191320@lists.php.net to get a copy of this message | ||
Easy way to short a string
<?php
function short_me($string, $long){
$short_string = (strlen($string) > $long ? substr($string, 0, $long) . "…"
: $string);
return $short_string;
}
$text = "Hello, this is an example."; // Lenght: 20
// Output
echo $text; // -> Hello, this is an example.
echo short_me($text, 8); // -> Hello, tâ¦
echo short_me($text, 5); // -> Helloâ¦
echo short_me($text, -5); // -> Hello, this is an exaâ¦
?>
Thanks to firepanther (www.coderz.pro)
----
Server IP: 213.172.110.14
Probable Submitter: 217.86.219.60
----
Manual Page -- http://www.php.net/manual/en/function.substr.php
Edit -- https://master.php.net/note/edit/110370
Del: integrated -- https://master.php.net/note/delete/110370/integrated
Del: useless -- https://master.php.net/note/delete/110370/useless
Del: bad code -- https://master.php.net/note/delete/110370/bad+code
Del: spam -- https://master.php.net/note/delete/110370/spam
Del: non-english -- https://master.php.net/note/delete/110370/non-english
Del: in docs -- https://master.php.net/note/delete/110370/in+docs
Del: other reasons-- https://master.php.net/note/delete/110370
Reject -- https://master.php.net/note/reject/110370
Search -- https://master.php.net/manage/user-notes.php