Some raw and useful helpers functions

Maintainers

Package info

github.com/straylightagency/php-helpers

pkg:composer/straylightagency/helpers

Statistics

Installs: 7

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.0 2026-01-26 17:33 UTC

This package is auto-updated.

Last update: 2026-02-26 18:10:34 UTC


README

Just some raw and useful helpers functions.

Installation

Require this package with composer.

composer require straylightagency/helpers

API Documentation

Format a comma separated float "65,25" into a regular dotted float "65.25", useful for pricing.

price_format(num: mixed, decimals: int = 2, decimal_separator: ?string = ".", thousands_separator: ?string = "" ): float

Check if an int|float value is within a certain bound. If the value is in range it returns the value, if the value is not in range it returns the nearest bound.

clamp(value: int|float, min: int|float, max: int|float): float|int

Get the contents of a svg file, applying a class list on it before returning if $class_list is not null.

svg_get_contents(file_path: string, class_list: ?string = null): string

Convert iso code to emoji.

iso_to_emoji(code: string): string

Same as array_map but the callback get the key associated to the value.

array_map_keys(callback: ?callable, array: array): array

Do a preg_match_all using callback with patterns.

preg_match_callback_array(patterns: array, subject: string): array

Equivalent to array_diff but recursively.

array_recursive_diff(a: array, b: array):array

Remove the first item(s) of an array if values are empty.

array_clean_first(array $array): array

Remove the last item(s) of an array if values are empty.

array_clean_last(array $array): array

Ensure the value is an array, otherwise returns an empty array. Avoid foreach error when the value is not an expected array.

array_safe(array: mixed): array

Explode a content string into an array of multiple lines based on carriage return characters.

split_content(string $content): array

Remove the <p></p> tags on a text.

strip_p(string $string): string

Easy way to split a text after $limit words without cutting through the middle of a word.

text_excerpt(string $text, int $limit = 35, string $end = '...'): string

Return a valid Google map url using address information provided. Second parameter itinerary allows to return an itinerary path instead of a pin on the map.

google_map_url(address: array, itinerary: bool = false): string

Find the ID of a video from the Vimeo url. Return null if it failed.

vimeo_id(vimeo_url: string): ?int

Find the ID of a video from the YouTube url. Return null if it failed.

youtube_id(youtube_url: string): ?string

Requirement

PHP 8.3 or above

See also

Credits

License

The MIT License (MIT).