承接 stk2k/string-format 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

stk2k/string-format

Composer 安装命令:

composer require stk2k/string-format

包简介

String formatter(C# String.Format/sprintf)

README 文档

README

Latest Version on Packagist Software License Build Status Coverage Status Code Climate Total Downloads

Description

String formatter(C# String.Format/sprintf)

Feature

  • Supports PHP sprintf formatter and C# String.Format formatter
  • You can implement your own formatter(StringFormatterInterface)
  • Implemented as a static method in trait

Usage

PHP sprintf formatter

use stk2k\string\format\test\classes\MyStringClass;
use stk2k\string\format\formatter\PhpSprintfStringFormatter;

MyStringClass::setStringFormatter(new PhpSprintfStringFormatter());
         
// string
echo MyStringClass::format('Hello, %s!', 'David');       // Hello, David!

// integer
echo MyStringClass::format('Come here after %d days', 3);       // Come here after 3 days
echo MyStringClass::format('%04d-%02d-%02d', 2021, 6, 10);      // 2021-06-10

// float
echo MyStringClass::format('%.03f', 3.1414926535);      // 3.141

// exponent
echo MyStringClass::format('%.3e', 362525200);      // 3.625e+8
echo MyStringClass::format('%.3E', 362525200);      // 3.625E+8

C# String.Format formatter

use stk2k\string\format\test\classes\MyStringClass;
use stk2k\string\format\formatter\PhpSprintfStringFormatter;
  
// string
echo MyStringClass::format('Hello, {0}!', 'David');       // Hello, David!

// integer
echo MyStringClass::format('Come here after {0:d} days', 3);       // Come here after 3 days
echo MyStringClass::format('{0:d4}-{1:d2}-{2:d2}', 2021, 6, 10);      // 2021-06-10

// float
echo MyStringClass::format('{0:F3}', 3.1414926535);      // 3.141

// exponent
echo MyStringClass::format('{0:e3}', 362525200);      // 3.625e+8
echo MyStringClass::format('{0:E3}', 362525200);      // 3.625E+8

// number
echo MyStringClass::format('{0:n}', 123456.789);      // 123,456.79
echo MyStringClass::format('{0:n3}', 123456.789);     // 123,456.789
echo MyStringClass::format('{0:n4}', 123456.789);     // 123,456.7890

// percentage
echo MyStringClass::format('Ratio: {0:P}', 0.18);      // Ratio: 18.00%
echo MyStringClass::format('Ratio: {0:P3}', 0.18);     // Ratio: 18.000%
echo MyStringClass::format('Ratio: {0:P4}', 0.18);     // Ratio: 18.0000%

// hexadecimal number
echo MyStringClass::format('{0:X}', 10);        // A
echo MyStringClass::format('{0:X3}', 10);       // 00A

Requirement

PHP 7.2 or later

Installing stk2k/string-format

The recommended way to install stk2k/string-format is through Composer.

composer require stk2k/string-format

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

License

This library is licensed under the MIT license.

Author

stk2k

Disclaimer

This software is no warranty.

We are not responsible for any results caused by the use of this software.

Please use the responsibility of the your self.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-06-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固