In PHP, is there an easy way to convert a number to a word? For instance, 27 to twenty-seven.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
I found some (2007/2008) source-code online and as it is copyright but I can use it freely and modify it however I want, so I place it here and re-license under CC-Wiki:
There's no built-in way that I'm aware of, but if you have a look at my example code for this question (in C#) it should be easy enough for you to get working. Basically it'd just be a matter of untyping the variables and adding the
$
prefix where appropriate and it should work.I needed a solution that put 'and' into the returned string and formatted it into a sentence - typically as a human would say it. So I adapted a different solution slightly - posted as I thought this could be useful for someone.
Code
Alternatively, you can use the NumberFormatter class from
intl
package in PHP . Here's a sample code to get you started (for commandline):I have generated this using a recursive function,.
I found two links for this. The first is a freeware PHP class you could use, the second is a example function you could have a look at and copy or use to write your own.