For this, at first use preg_split() and set the function with this −
'//u'
After setting like above, the empty delimiter issue will get fixed, since we added '//u' above.
Example
The PHP code is as follows
<!DOCTYPE html>
<html>
<body>
<?php
$stringValues="";
$result= preg_split('//u', $stringValues,-1, PREG_SPLIT_NO_EMPTY);
print_r($result);
echo "<br>";
$stringValues1="John Smith";
$result1= preg_split('//u', $stringValues1,-1, PREG_SPLIT_NO_EMPTY);
print_r($result1);
?>
</body>
</html>Output
This will produce the following output −
Array ( ) Array ( [0] => J [1] => o [2] => h [3] => n [4] => [5] => S [6] => m [7] => i [8] => t [9] => h )