note 60548 added to function.substr

From: Date: Tue, 10 Jan 2006 21:34:43 +0000
Subject: note 60548 added to function.substr
Groups: php.notes 
Request: Send a blank email to php-notes+get-101520@lists.php.net to get a copy of this message
Add on to "Matias from Argentina" str_format_number function. Just added handling of $String shorter then $Format by adding a side to start the fill and a string length to the while loop. function str_format_number($String, $Format, $Start = 'left'){ //If we want to fill from right to left incase string is shorter then format if ($Start == 'right') { $String = strrev($String); $Format = strrev($Format); } if($Format == '') return $String; if($String == '') return $String; $Result = ''; $FormatPos = 0; $StringPos = 0; while ((strlen($Format) - 1) >= $FormatPos && strlen($String) > $StringPos) { //If its a number => stores it if (is_numeric(substr($Format, $FormatPos, 1))) { $Result .= substr($String, $StringPos, 1); $StringPos++; //If it is not a number => stores the caracter } else { $Result .= substr($Format, $FormatPos, 1); } //Next caracter at the mask. $FormatPos++; } if ($Start == 'right') $Result = strrev($Result); return $Result; } ---- Manual Page -- http://www.php.net/manual/en/function.substr.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60548 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60548&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60548&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60548&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60548&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60548&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60548&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60548&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60548&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101520) next »