项目作者: coduo

项目描述 :
Cast any php value into a string
高级语言: PHP
项目地址: git://github.com/coduo/php-to-string.git
创建时间: 2014-05-04T10:28:40Z
项目社区:https://github.com/coduo/php-to-string

开源协议:MIT License

下载


PHP To String

Simple library that converts PHP values into strings.

Status:

Build Status
Latest Stable Version
Total Downloads
Latest Unstable Version
License

Simple library that allows you to cast any php value into string

Installation

  1. composer require coduo/php-to-string

Usage

Supported types:

  • string
  • integer
  • float/double
  • object
  • callable
  • array
  • resource
  1. use Coduo\ToString\StringConverter;
  2. $string = new StringConverter('foo');
  3. echo $string; // "foo"
  4. $double = new StringConverter(1.12312);
  5. echo $double; // "1.12312"
  6. $integer = new StringConverter(1);
  7. echo $integer; // "1"
  8. $datetime = new StringConverter(new \DateTime());
  9. echo $datetime; // "\DateTime"
  10. $array = new StringConverter(['foo', 'bar', 'baz']);
  11. echo $array; // "Array(3)"
  12. $res = fopen(sys_get_temp_dir() . "/foo", "w");
  13. $resource = new StringConverter($res);
  14. echo $resource; // "Resource(stream)"