note 94707 added to function.str-pad

From: Date: Thu, 19 Nov 2009 17:52:12 +0000
Subject: note 94707 added to function.str-pad
Groups: php.notes 
Request: Send a blank email to php-notes+get-163091@lists.php.net to get a copy of this message
Convenience functions (perhaps these should be added as native functions if popular?): <?php function str_lpad( &$s, &$l, &$p = ' ' ) { return str_pad( $s, $l, $p, STR_PAD_LEFT ); } function str_nlpad( &$s, &$l ) { return str_lpad( $s, $l, '0' ); } function str_npad( &$s, &$l ) { return str_pad( $s, $l, '0' ); } ?> E.g.: <?php $mystr = str_nlpad( $mystr, 4 ) ?> Are more concise, semantically coherent, and perhaps also more efficient because do not create an intermediate discarded string, than the clever: http://www.php.net/manual/en/function.str-pad.php#14585 <?php $mystr = substr("0000$mystr",-4) ?> ---- Server IP: 69.147.83.197 Probable Submitter: 121.97.54.2 (proxied: 121.97.54.144) ---- Manual Page -- http://www.php.net/manual/en/function.str-pad.php Edit -- https://master.php.net/note/edit/94707 Del: integrated -- https://master.php.net/note/delete/94707/integrated Del: useless -- https://master.php.net/note/delete/94707/useless Del: bad code -- https://master.php.net/note/delete/94707/bad+code Del: spam -- https://master.php.net/note/delete/94707/spam Del: non-english -- https://master.php.net/note/delete/94707/non-english Del: in docs -- https://master.php.net/note/delete/94707/in+docs Del: other reasons-- https://master.php.net/note/delete/94707 Reject -- https://master.php.net/note/reject/94707 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#163091) next »