Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeijei4/php_stringify
https://github.com/jeijei4/php_stringify
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/jeijei4/php_stringify
- Owner: jeijei4
- Created: 2024-02-15T14:46:56.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-02-15T14:53:50.000Z (12 months ago)
- Last Synced: 2024-11-13T10:44:08.042Z (3 months ago)
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP stringify
```php
stringify(
$formatter->format(new DateTimeImmutable(
$value->format("Y-m-d H:i:s.vp"),
$timezone
))
);
}return $this->stringify($value->format("Y-m-d H:i:s.vp"));
}if ($value instanceof UnitEnum) {
return $value->name;
}if (is_object($value)) {
if (method_exists($value, '__toString')) {
return $this->stringify($value->__toString());
}return json_encode($value, JSON_PRETTY_PRINT);
}if (is_array($value)) {
return json_encode($value, JSON_PRETTY_PRINT);
}if (is_string($value)) {
return '"' . $value . '"';
}if (is_resource($value)) {
return 'resource;' . get_resource_type($value);
}if (null === $value) {
return 'null';
}if (false === $value) {
return 'false';
}if (true === $value) {
return 'true';
}if (is_scalar($value)) {
$val = (string)$value;if (mb_strlen($val) > 100) {
return mb_substr($val, 0, 97) . "...";
}return $val;
}return gettype($value);
}
```