https://github.com/coduo/php-to-string
Cast any php value into a string
https://github.com/coduo/php-to-string
cast php string
Last synced: 7 months ago
JSON representation
Cast any php value into a string
- Host: GitHub
- URL: https://github.com/coduo/php-to-string
- Owner: coduo
- License: mit
- Created: 2014-05-04T10:28:40.000Z (over 11 years ago)
- Default Branch: 3.x
- Last Pushed: 2024-11-06T20:13:04.000Z (about 1 year ago)
- Last Synced: 2025-06-03T06:10:45.643Z (7 months ago)
- Topics: cast, php, string
- Language: PHP
- Homepage:
- Size: 293 KB
- Stars: 262
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP To String
Simple library that converts PHP values into strings.
Status:

[](https://packagist.org/packages/coduo/php-to-string)
[](https://packagist.org/packages/coduo/php-to-string)
[](https://packagist.org/packages/coduo/php-to-string)
[](https://packagist.org/packages/coduo/php-to-string)
Simple library that allows you to cast any php value into string
## Installation
```
composer require coduo/php-to-string
```
## Usage
Supported types:
* string
* integer
* float/double
* object
* callable
* array
* resource
```php
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)"
```