\DevOwl\FastHtmlTagUtils

Utility helpers.

Summary

Methods
Properties
Constants
startsWith()
endsWith()
isJson()
isHtml()
isBase64DataUrl()
isBinary()
preg_replace_callback_recursive()
preg_jit_safe()
parseHtmlAttributes()
legacy_html_attributes_parser()
htmlAttributes()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

startsWith()

startsWith(string  $haystack,string  $needle)

Check if a string starts with a given needle.

Parameters

string $haystack

The string to search in

string $needle

The starting string

endsWith()

endsWith(string  $haystack,string  $needle)

Check if a string starts with a given needle.

Parameters

string $haystack

The string to search in

string $needle

The starting string

isJson()

isJson(string  $string): array|false

Check if passed string is JSON.

Parameters

string $string

Returns

array|false

isHtml()

isHtml(string  $string)

Check if a passed string is HTML.

Parameters

string $string

isBase64DataUrl()

isBase64DataUrl(string  $str)

Check if a given string is a base64-encoded data URL and return decoded string and mime type.

It does not support binary data and returns false!

Parameters

string $str

isBinary()

isBinary(string  $str)

Check if a string is binary.

Parameters

string $str

preg_replace_callback_recursive()

preg_replace_callback_recursive(string  $pattern,callable  $callback,string  $subject)

A modified version of `preg_replace_callback` that is executed multiple times until no longer match is given.

Parameters

string $pattern
callable $callback
string $subject

preg_jit_safe()

preg_jit_safe(string  $pattern,callback  $callback)

If a PHP environment is using the PCRE JIT compiler, all `preg_replace` functions will return an empty result. Instead, we could potentially bypass this by disabling the JIT compiler for a specific pattern with the runtime configuration `pcre.jit`.

This utility function allows you to pass your regular expression and additionally a callback which should do the preg_replace.

Example:

preg_jit_safe($pattern, function ($usePattern) {
    return preg_replace_callback($usePattern, ...);
});

Practically, if your pattern runs on a JIT error, the JIT compiler will be temporarily disabled, creates a modified pattern (which indeed matches your groups!) which bypasses the PCRE pattern cache and passes the pattern to your callback.

Parameters

string $pattern
callback $callback

parseHtmlAttributes()

parseHtmlAttributes(string  $str)

Parse a HTML attributes string to an associative array.

Parameters

string $str

legacy_html_attributes_parser()

legacy_html_attributes_parser(string  $text)

Ported from [WordPress](https://developer.wordpress.org/reference/functions/shortcode_parse_atts/).

Why a port? This package should be framework-agnostic and we do not want to be rely on WordPress.

Parameters

string $text

htmlAttributes()

htmlAttributes(array  $attributes)

Transform a given associate attributes array to a DOM attributes string.

Parameters

array $attributes