note 93993 added to function.substr-replace
| From: | kalim dot fleet at gmail dot com | Date: | Sat, 10 Oct 2009 16:49:19 +0000 |
| Subject: | note 93993 added to function.substr-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-161620@lists.php.net to get a copy of this message | ||
This will truncate a longer string to a smaller string of specified length while replacing the
middle portion with a separator exactly in the middle.
<?php
$longString = 'abcdefghijklmnopqrstuvwxyz0123456789z.jpg';
$separator = '/.../';
$separatorlength = strlen($separator) ;
$maxlength = 25 - $separatorlength;
$start = $maxlength / 2 ;
$trunc = strlen($longString) - $maxlength;
echo substr_replace($longString, $separator, $start, $trunc);
//prints "abcdefghij/.../56789z.jpg"
?>
----
Server IP: 192.41.40.227
Probable Submitter: 68.198.215.85
----
Manual Page -- http://www.php.net/manual/en/function.substr-replace.php
Edit -- https://master.php.net/note/edit/93993
Del: integrated -- https://master.php.net/note/delete/93993/integrated
Del: useless -- https://master.php.net/note/delete/93993/useless
Del: bad code -- https://master.php.net/note/delete/93993/bad+code
Del: spam -- https://master.php.net/note/delete/93993/spam
Del: non-english -- https://master.php.net/note/delete/93993/non-english
Del: in docs -- https://master.php.net/note/delete/93993/in+docs
Del: other reasons-- https://master.php.net/note/delete/93993
Reject -- https://master.php.net/note/reject/93993
Search -- https://master.php.net/manage/user-notes.php