RE: Ensure a number is three digits long

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



You should be able to do this quite well with the str_pad() function.

http://us3.php.net/manual/en/function.str-pad.php

-M 

> -----Original Message-----
> From: Shaun [mailto:shaunthornburgh@xxxxxxxxxxx] 
> Sent: Sunday, February 13, 2005 12:09 PM
> To: php-general@xxxxxxxxxxxxx
> Subject:  Ensure a number is three digits long
> 
> Hi,
> 
> I have am trying to create functions to convert strings to 
> ascii and vice
> versa:
> 
> function string_to_ascii( $str ) {
>  for( $i=0; $i < strlen( $str ); $i++ ) {
>    $asc .= ord( substr( $str, $i ) );
>   }
>  return $asc;
> }
> 
> This function works fine, however I need to ensure that the 
> ASCII convertions are three digits long so that I know where 
> to split the ASCII string when converting back to a normal 
> string. i.e. 97 must be 097.
> 
> Thanks for any advice offered 
> 
> --
> PHP General Mailing List (http://www.php.net/) To 
> unsubscribe, visit: http://www.php.net/unsub.php
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux