定制 ryangjchandler/f 二次开发

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

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

ryangjchandler/f

最新稳定版本:v1.0.0

Composer 安装命令:

composer require ryangjchandler/f

包简介

Nicer string formatting for PHP, inspired by Rust, Python and others.

README 文档

README

f() is an alternative to string concatenation and PHP's sprintf() function. It takes inspiration from how Rust handles string formatting with the format!() macro.

It doesn't currently do everything that sprintf() does, but it does enough to be useful.

Installation

You can install the package using Composer:

composer require ryangjchandler/f

Usage

Once installed, the package will provide a global f() function that you can start using straight away.

f('Hello, {}', 'Ryan');

If you've already got an f() function registered in the global namespace, or despise global helper functions, you can use the RyanChandler\F\F class instead.

use RyanChandler\F\F;

F::format('Hello, {}', 'Ryan');

Placeholder Syntax

The {} syntax you see above is known as a placeholder. This is where the arguments you pass to f() will be injected into the string.

Placeholder Description Example Result
{} References an argument based on the position of the placeholder in the format string. f('Hello, {}. I am {}.', 'world', 'Ryan') Hello, world. I am Ryan.
{2} References the 3rd argument (0-based indexing). f('{}, {}, {}, {2}', 1, 2, 3) 1, 2, 3, 3
{name} References a named argument. f('Hello, {name}', name: "Ryan") Hello, Ryan
{:b} Formats an integer as binary. f('{:b}', 42) 101010
{:x} Formats an integer as hexadecimal. f('{:x}', 42) 2a
{:o} Formats an integer as octal. f('{:o}', 42) 52
{:>10} Right-justifies the argument to a width of 10 using a single space. f('{:>10}', 'Hello')      Hello
{:<10} Left-justifies the argument to a width of 10 using a single space. f('{:>10}', 'Hello') Hello     
{:0>10} Right-justifies the argument to a width of 10 using a custom character 0. f('{:0>10}', '12345') 0000012345
{:0<10} Left-justifies the argument to a width of 10 using a custom character 0. f('{:0>10}', '12345') 1234500000
{:>width$} Right-justifies the argument to a width defined by the named argument width. f('{:>width$}', 'Hello', width: 7)   Hello

Contributing

All contributions are appreciated and welcome. Please refer to the CONTRIBUTING document for more information on how to contribute.

Credits

License

This project is licensed under the MIT license. Please refer to the LICENSE document for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固