<?php

namespace Openguru\OpenCartFramework\Support;

class Str
{
    /**
     * Determine if a given string starts with a given substring.
     *
     * @param string $haystack The string to search in.
     * @param string|array $needles The substring(s) to search for.
     * @return bool True if the string starts with any of the given substrings, false otherwise.
     */
    public static function startsWith(string $haystack, $needles): bool
    {
        foreach ((array) $needles as $needle) {
            if ($needle === '') {
                if ($haystack === '') {
                    return true;
                }
                continue;
            }

            if (strncmp($haystack, $needle, strlen($needle)) === 0) {
                return true;
            }
        }

        return false;
    }

    public static function htmlEntityEncode(string $string): string
    {
        return html_entity_decode($string, ENT_QUOTES | ENT_HTML5, 'UTF-8');
    }
}
