How to deal with multi-byte UTF-8 strings in JavaScript and fix the empty delimiter/separator issue



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

 Live Demo

<!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 )
Updated on: 2020-10-13T07:59:11+05:30

252 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements