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 |
Utility helpers.
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.
string | $pattern | |
callback | $callback |