如何使用php5将整数值转换为word格式?
我想将数字转换为word格式。
例如:
$count = 5;
echo "Hello Mr user this is your ".$count." review."
我需要这样的输出......
“用户先生您好,这是您的第五条评论。”
I want to convert a number to word format.
For example:
$count = 5;
echo "Hello Mr user this is your ".$count." review."
I need output like this...
"Hello Mr user this is your fifth review."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在另一个 StackOverflow 线程中检查这一点:
将数字转换为其字符串表示形式
Check this in another StackOverflow thread:
Convert a number to its string representation
php 中没有内置函数可以实现这一点。但尝试外部库,例如: http://pear.php.net/package/Numbers_Words
There is no built in function in php to make that. But try external lib like : http://pear.php.net/package/Numbers_Words
如果您指的是内置函数,则不,PHP 没有内置函数。但您可以创建自己的。
如果您只查看英文数字,那么这不是什么大问题。但是,如果您需要处理外语(例如阿拉伯语),则必须做一些额外的工作,因为数字和物体都有性别。所以算法变得有点复杂。
郑重声明一下,我正在开发一个阿拉伯语开源转换工具。
If you're referring to a built-in function, no, PHP does not have one. But You can create your own.
If you're looking at only English numbers, it's not much of an issue. But if you need to deal with a foreign language (like Arabic), you have to do a bit of extra work since numbers and objects have genders. So the algorithm gets a little more complex.
Just for the record, I'm working on producing an open source conversion tool for Arabic.
我知道这并不完全是你想要的,但我从 php.net 上某个地方的评论中找到了这个(找不到源代码),它适用于像
1st
,第 243 位
和第 85 位
。为了可读性和简单性,您甚至可能想考虑这种格式,具体取决于您期望数字有多高。如果它们少于 100,您应该能够轻松编写自己的函数。然而,如果他们能变得非常高:
听起来有点尴尬:)
希望这对一些人有帮助。
I know this isn't exactly what you're after, but I picked this up from the comments on php.net somewhere (can't find source), it works for output like
1st
,243rd
and85th
.You might want to even consider this format anyways for readability and simplicity, depending on how high you expect the numbers to be. If they are less than 100, you should be able to write your own function easily. However, if they can get really high:
Sounds a bit awkward :)
Hope this helps some.