coduo / php-to-string
将 PHP 值转换为字符串的简单库
3.2.1
2023-03-28 10:10 UTC
Requires
- php: >=7.2
Suggests
- ext-intl: Required if you are going to use humanizer with locales different than en_EN
README
将 PHP 值转换为字符串的简单库。
状态
将任何 PHP 值转换为字符串的简单库
安装
composer require coduo/php-to-string
用法
支持类型
- 字符串
- 整数
- 浮点数/双精度浮点数
- 对象
- 可调用
- 数组
- 资源
use Coduo\ToString\StringConverter; $string = new StringConverter('foo'); echo $string; // "foo" $double = new StringConverter(1.12312); echo $double; // "1.12312" $integer = new StringConverter(1); echo $integer; // "1" $datetime = new StringConverter(new \DateTime()); echo $datetime; // "\DateTime" $array = new StringConverter(['foo', 'bar', 'baz']); echo $array; // "Array(3)" $res = fopen(sys_get_temp_dir() . "/foo", "w"); $resource = new StringConverter($res); echo $resource; // "Resource(stream)"