Sourcecode

Captcha/de/themarcraft/utils/Utils.php


Utils.php

<?php
namespace de\themarcraft\utils;

/**
 * TMCZ Utils
 * Different Methods for more efficient coding
 * @author Marvin Niermann <[email protected]>
 * @version 22.11.2024
 * @copyright 2024 themarcraft.de
 */
class Utils
{

    /**
     * Remove every HTML or PHP Tag from a string to get plain text
     * @param $string string
     * @return array|string|null
     */
    public static function removeTags(string $string): array|string|null
    {

        //$string = str_ireplace("<br>", "[tmczln]", $string);

        $pattern = '/<[^>]*>/';

        $new_string = preg_replace($pattern, '', $string);

        $pattern2 = '/<?[^>]*?>/';

        $new_string2 = preg_replace($pattern2, '', $new_string);

        //$new_string = str_ireplace("[tmczln]", "<br>", $new_string);

        return $new_string2;
    }

    public static function getRandomString(int $length): string
    {
        $pattern = "abcefghijkmoABCDEFGHJKLMNPQRSTUVWY1234578";

        $rs = str_shuffle($pattern);
        return substr($rs, 0, $length);
    }
}