Page 1 of 1

easy way to covert 1 (as number) to one (as word)

Posted: Sun Jan 21, 2007 3:37 pm
by spamyboy
is there any easy way to covert 1 (as number) to one (as word) ?
numbers as numbers to numbers as words.

Posted: Sun Jan 21, 2007 3:45 pm
by matthijs
Don't think there's a standard function for that, but you could see if str_replace() or a related function could do something for you.

Posted: Sun Jan 21, 2007 4:00 pm
by spamyboy
Yeah, it's exactly what I was asking for is there such function that do that.

Posted: Sun Jan 21, 2007 4:05 pm
by hawleyjr
spamyboy wrote:Yeah, it's exactly what I was asking for is there such function that do that.

There is not a function for that...However, it would be fairly simple to write one ;)

Posted: Sun Jan 21, 2007 4:24 pm
by spamyboy
Yeah.. But what if I set replacment for number 1 to one, and there would be number 11 so script would show it as oneone :|

Posted: Sun Jan 21, 2007 4:47 pm
by hawleyjr
Here is a start ;)

Code: Select all

function digsToWords( $num ){

	//VALIDATE NUMBER HERE
	
	
	switch( $num ){
	
		case ( $num < 10 ):
			return getNumLessThanTen( $num );
		break;
		case ( $num < 20 ):
			case 11:
				return 'eleven';
			break;
			case 12:
				return 'twelve';
			break;
			case 13:
				return 'thirteen';
			break;
			.
			..
			...
			....
		case ( $num < 30 ):
			return 'twenty ' . getNumLessThanTen( $num );
		break;
		.
		..
		...
		....
	}
}

function getNumLessThanTen( $num ){

	//VALIDATE NUMBER HERE
	
	
	switch( $num ){
	
		case 1:
			return 'one';
		break;
		case 2:
			return 'two';
		break;
		case 3:
			return 'three';
		break;
		.
		..
		...
		....
	}

}

Posted: Sun Jan 21, 2007 4:49 pm
by Ambush Commander