You want to be using the SPELLOUT
format style, rather thanORDINAL
.
The next problem is how to tell the formatter to use the particular ruleset that you are interested in; namely %spellout-ordinal
. This can be done by using setTextAttribute()
.
Example
$formatter = new NumberFormatter('en_US', NumberFormatter::SPELLOUT);
$formatter->setTextAttribute(NumberFormatter::DEFAULT_RULESET,
"%spellout-ordinal");
for ($i = 1; $i <= 5; $i++) {
echo $formatter->format($i) . PHP_EOL;
}
Output
first
second
third
fourth
fifth