<tfoot id='Tca79'></tfoot>
    <i id='Tca79'><tr id='Tca79'><dt id='Tca79'><q id='Tca79'><span id='Tca79'><b id='Tca79'><form id='Tca79'><ins id='Tca79'></ins><ul id='Tca79'></ul><sub id='Tca79'></sub></form><legend id='Tca79'></legend><bdo id='Tca79'><pre id='Tca79'><center id='Tca79'></center></pre></bdo></b><th id='Tca79'></th></span></q></dt></tr></i><div id='Tca79'><tfoot id='Tca79'></tfoot><dl id='Tca79'><fieldset id='Tca79'></fieldset></dl></div>

        <bdo id='Tca79'></bdo><ul id='Tca79'></ul>
      1. <small id='Tca79'></small><noframes id='Tca79'>

      2. <legend id='Tca79'><style id='Tca79'><dir id='Tca79'><q id='Tca79'></q></dir></style></legend>

        在 PHP 中将单词转换为数字

        时间:2024-08-15
      3. <legend id='Ja8Zk'><style id='Ja8Zk'><dir id='Ja8Zk'><q id='Ja8Zk'></q></dir></style></legend>

                <bdo id='Ja8Zk'></bdo><ul id='Ja8Zk'></ul>
                <tfoot id='Ja8Zk'></tfoot>

                <small id='Ja8Zk'></small><noframes id='Ja8Zk'>

                    <tbody id='Ja8Zk'></tbody>
                • <i id='Ja8Zk'><tr id='Ja8Zk'><dt id='Ja8Zk'><q id='Ja8Zk'><span id='Ja8Zk'><b id='Ja8Zk'><form id='Ja8Zk'><ins id='Ja8Zk'></ins><ul id='Ja8Zk'></ul><sub id='Ja8Zk'></sub></form><legend id='Ja8Zk'></legend><bdo id='Ja8Zk'><pre id='Ja8Zk'><center id='Ja8Zk'></center></pre></bdo></b><th id='Ja8Zk'></th></span></q></dt></tr></i><div id='Ja8Zk'><tfoot id='Ja8Zk'></tfoot><dl id='Ja8Zk'><fieldset id='Ja8Zk'></fieldset></dl></div>
                  本文介绍了在 PHP 中将单词转换为数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将写为单词的数值转换为整数.例如,iPhone有二十三万七百八十三个应用程序"会成为iPhone 作为 230783 个应用程序"

                  I am trying to convert numerical values written as words into integers. For example, "iPhone has two hundred and thirty thousand seven hundred and eighty three apps" would become "iPhone as 230783 apps"

                  在我开始编码之前,我想知道是否存在任何用于此转换的函数/代码.

                  Before i start coding, I would like to know if any function / code exists for this conversion.

                  推荐答案

                  有很多页面讨论从数字到单词的转换.反方向没有那么多.我能找到的最好的是 Ask Yahoo 上的一些伪代码.请参阅 http://answers.yahoo.com/question/index?qid=20090216103754AAONnDz 一个不错的算法:

                  There are lots of pages discussing the conversion from numbers to words. Not so many for the reverse direction. The best I could find was some pseudo-code on Ask Yahoo. See http://answers.yahoo.com/question/index?qid=20090216103754AAONnDz for a nice algorithm:

                  嗯,总的来说,您要做两件事:查找标记(转换为数字的单词)和应用语法.简而言之,您正在为一种非常有限的语言构建解析器.

                  Well, overall you are doing two things: Finding tokens (words that translates to numbers) and applying grammar. In short, you are building a parser for a very limited language.

                  您需要的令牌是:

                  功率:千、百万、十亿
                  百:百
                  十:二十、三十……九十
                  单位:一、二、三、...九、
                  特殊:十、十一、十二、……十九

                  POWER: thousand, million, billion
                  HUNDRED: hundred
                  TEN: twenty, thirty... ninety
                  UNIT: one, two, three, ... nine,
                  SPECIAL: ten, eleven, twelve, ... nineteen

                  (删除任何和",因为它们没有意义.将连字符分成两个标记.即 65 应该被处理为六十"五")

                  (drop any "and"s as they are meaningless. Break hyphens into two tokens. That is sixty-five should be processed as "sixty" "five")

                  标记字符串后,从右移到左.

                  Once you've tokenized your string, move from RIGHT TO LEFT.

                  1. 从 RIGHT 中抓取所有标记,直到您击中 POWER 或整个字符串.

                  1. Grab all the tokens from the RIGHT until you hit a POWER or the whole string.

                  解析这些模式的停止点之后的标记:

                  Parse the tokens after the stop point for these patterns:

                  特别
                  十个
                  单位
                  十个单位
                  单位百
                  单位百特
                  单位 10
                  单位百单位
                  单位一百十单位

                  SPECIAL
                  TEN
                  UNIT
                  TEN UNIT
                  UNIT HUNDRED
                  UNIT HUNDRED SPECIAL
                  UNIT HUNDRED TEN
                  UNIT HUNDRED UNIT
                  UNIT HUNDRED TEN UNIT

                  (假设此语法中不允许使用一千七百")

                  (This assumes that "seventeen hundred" is not allowed in this grammar)

                  这将为您提供号码的最后三位.

                  This gives you the last three digits of your number.

                  如果你停在整个字符串,你就完成了.

                  If you stopped at the whole string you are done.

                  如果你停在一个功率,从第 1 步重新开始,直到你达到更高的功率或整个字符串.

                  If you stopped at a power, start again at step 1 until you reach a higher POWER or the whole string.

                  这篇关于在 PHP 中将单词转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 PHP 中显示带序号后缀的数字 下一篇:从 PHP 中的小数中删除无用的零位

                  相关文章

                  <legend id='27BdO'><style id='27BdO'><dir id='27BdO'><q id='27BdO'></q></dir></style></legend>

                  <small id='27BdO'></small><noframes id='27BdO'>

                  • <bdo id='27BdO'></bdo><ul id='27BdO'></ul>
                • <tfoot id='27BdO'></tfoot>
                  <i id='27BdO'><tr id='27BdO'><dt id='27BdO'><q id='27BdO'><span id='27BdO'><b id='27BdO'><form id='27BdO'><ins id='27BdO'></ins><ul id='27BdO'></ul><sub id='27BdO'></sub></form><legend id='27BdO'></legend><bdo id='27BdO'><pre id='27BdO'><center id='27BdO'></center></pre></bdo></b><th id='27BdO'></th></span></q></dt></tr></i><div id='27BdO'><tfoot id='27BdO'></tfoot><dl id='27BdO'><fieldset id='27BdO'></fieldset></dl></div>