note 76873 added to function.substr

From: Date: Fri, 03 Aug 2007 07:39:12 +0000
Subject: note 76873 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-129144@lists.php.net to get a copy of this message
Quick function to trim urls for display, see http://www.bayofislands.net/news/ for live use. Can no doubt be done better but this works... <? // linkLimit($string, $length = 60, $ellipsis = '&hellip;') // $length = max characters with a space in the middle function linkLimit($string, $length = 30, $ellipsis = '&hellip;') { $string = preg_replace('#^http://(www.)?#','',$string); if( strlen($string) >= $length ) { return substr($string, 0, ($length/2)) . $ellipsis . substr($string, (strlen($string) - ($length/2)), ($length/2)); } else { return $string; } } $source_url = 'http://www.bayofislands.net/accommodation/backpackers/'; echo linkLimit($source_url);// returns 'bayofislands.ne…on/backpackers/' exit; ?> ---- Server IP: 130.206.1.5 Probable Submitter: 87.223.255.194 ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- https://master.php.net/note/edit/76873 Del: integrated -- https://master.php.net/note/delete/76873/integrated Del: useless -- https://master.php.net/note/delete/76873/useless Del: bad code -- https://master.php.net/note/delete/76873/bad+code Del: spam -- https://master.php.net/note/delete/76873/spam Del: non-english -- https://master.php.net/note/delete/76873/non-english Del: in docs -- https://master.php.net/note/delete/76873/in+docs Del: other reasons-- https://master.php.net/note/delete/76873 Reject -- https://master.php.net/note/reject/76873 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129144) next »