| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- declare(strict_types=1);
- namespace App\Service\Utils;
- use App\Tests\Service\Utils\StringsUtilsTest;
- /**
- * Class StringsUtils : méthodes d'aide pour la gestion de string.
- * @package App\Service\Utils
- */
- class StringsUtils
- {
- /**
- * Supprime les quotes d'une chaine de caractères
- * @param string $str
- * @return string
- * @see StringsUtilsTest::testUnquote()
- */
- public static function unquote(string $str): string {
- return str_replace("'", "", $str);
- }
- /**
- * Convert CamelCase formatted string into snake_case
- * @see https://stackoverflow.com/a/40514305/4279120
- *
- * @param string $string
- * @param string $sep
- * @return string
- *
- * @see StringsUtilsTest::testCamelToSnake()
- */
- public static function camelToSnake(string $string, string $sep = "_"): string {
- return strtolower(
- preg_replace(
- '/(?<=\d)(?=[A-Za-z])|(?<=[A-Za-z])(?=\d)|(?<=[a-z])(?=[A-Z])/',
- $sep,
- $string
- )
- );
- }
- /**
- * @param string $html
- * @return string
- *
- * @see StringsUtilsTest::testConvertHtmlToText()
- */
- public function convertHtmlToText(string $html): string
- {
- return strip_tags(preg_replace('{<(head|style)\b.*?</\1>}is', '', $html));
- }
- }
|