定制 prfardin/php-persian-number-to-words 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prfardin/php-persian-number-to-words

最新稳定版本:v1.0.1

Composer 安装命令:

composer require prfardin/php-persian-number-to-words

包简介

Converts number to words in persian

README 文档

README

Latest Version on Packagist Total Downloads Repo Size Repo Size

This packages offers ability to convert numbers to words in persian. Words and phrases are fully configurable, so it is possible to use it for all persian language family with configuration.

Requirement

This package requires PHP 7.4 or higher.

Installation

You can install the package via composer:

composer require prfardin/php-persian-number-to-words

Usage

$dictionary = new prfardin\PersianNumberToWords\Dictionary();

$converter = new prfardin\PersianNumberToWords\PersianNumberToWords($dictionary);

echo $converter->convert(0);
// صفر

echo $converter->convert(-10);
// منفی ده

echo $converter->convert(229);
// دویست و بیست و نه

echo $converter->convert(999999999);
// نهصد و نود و نه میلیون و نهصد و نود و نه هزار و نهصد و نود و نه

Configuration

It is possible to customize the way output should look like using Dictionary class setter methods.

$dictionary = (new prfardin\PersianNumberToWords\Dictionary())
    ->setZero('هیچ')
    ->setNegative('منهای')
    ->setSeparator(' ُ ');

// Also ->setUnits(array $units) & -> setSuffixes(array $suffixes) are availabe

$converter = new prfardin\PersianNumberToWords\PersianNumberToWords($dictionary);

echo $converter->convert(0);
// هیچ

echo $converter->convert(-10);
// منهای ده

echo $converter->convert(229);
// دویست ُ بیست ُ نه

Default Configuration

This code is a part of Dictionary class, you can see all default Configuration:

class Dictionary
{

    protected string $zero = 'صفر';

    protected string $negative = 'منفی';

    protected string $separator = " و ";

    protected array $units = [
        1 => 'یک',
        2 => 'دو',
        3 => 'سه',
        4 => 'چهار',
        5 => 'پنج',
        6 => 'شش',
        7 => 'هفت',
        8 => 'هشت',
        9 => 'نه',
        10 => 'ده',
        11 => 'یازده',
        12 => 'دوازده',
        13 => 'سیزده',
        14 => 'چهارده',
        15 => 'پانزده',
        16 => 'شانزده',
        17 => 'هفده',
        18 => 'هجده',
        19 => 'نوزده',
        20 => 'بیست',
        30 => 'سی',
        40 => 'چهل',
        50 => 'پنجاه',
        60 => 'شصت',
        70 => 'هفتاد',
        80 => 'هشتاد',
        90 => 'نود',
        100 => 'صد',
        200 => 'دویست',
        300 => 'سیصد',
        400 => 'چهارصد',
        500 => 'پانصد',
        600 => 'ششصد',
        700 => 'هفتصد',
        800 => 'هشتصد',
        900 => 'نهصد'
    ];

    protected array $suffixes = [
        3 => 'هزار',
        6 => 'میلیون',
        9 => 'میلیارد',
        12 => 'بیلیون',
        15 => 'بیلیارد',
        18 => 'تریلیون',
        21 => 'تریلیارد',
        24 => 'کوآدریلیون',
        27 => 'کادریلیارد',
        30 => 'کوینتیلیون',
        33 => 'کوانتینیارد',
        36 => 'سکستیلیون',
        39 => 'سکستیلیارد',
        42 => 'سپتیلیون',
        45 => 'سپتیلیارد',
        48 => 'اکتیلیون',
        51 => 'اکتیلیارد',
        54 => 'نانیلیون',
        57 => 'نانیلیارد',
        60 => 'دسیلیون',
        63 => 'دسیلیارد',
    ];

    // Setters & Helpers...

}

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-30