I need to convert strings of the form
\"a b c\"
into arrays of the form
Array
(
[0] => a
[1] => a b
[2] =
This works and it works also with multibyte strings, all the methods above don't, they return null and duplicated values.
function substrings($str, $charset = 'UTF-8') {
$length = mb_strlen($str, $charset);
$subs = [];
for ($i = 0; $i < $length; $i++)
for ($j = 1; $j <= $length; $j++)
$subs[] = mb_substr($str, $i, $j, $charset);
return array_unique($subs);
}
print_r(substrings("php"));