Skip to content

Instantly share code, notes, and snippets.

View w3spi5's full-sized avatar
🏠
Working from home

w3spi5 w3spi5

🏠
Working from home
View GitHub Profile
@w3spi5
w3spi5 / utf8ize.php
Last active March 10, 2024 17:25
Recursively converts data (strings, arrays, objects) to UTF-8 encoding.
<?php
/**
* Related with utf8 problems and based on differents answers from https://stackoverflow.com/a/19366999/3452348
* This function is at the time of writing, for me, the best improved version existing actually.
*
* This function is designed to uniformly encode data as UTF-8. It handles strings by attempting
* to detect the current encoding and converting it to UTF-8. For arrays and objects, it applies
* the conversion recursively to each element or property. The function tries a predefined list
* of common encodings if automatic detection fails. Note that only public properties of objects
@w3spi5
w3spi5 / isLocal.php
Last active March 10, 2024 17:32
PHP - One line static function to check if you are in local or prod env
<?php
public static function isLocal(): bool
{
return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']);
}