- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
<!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 )
- Related Articles
- How to represent Unicode strings as UTF-8 encoded strings using Tensorflow and Python?
- How can Tensorflow text be used to split the UTF-8 strings in Python?
- How many bits are used to represent Unicode, ASCII, UTF-16, and UTF-8 characters in java?
- Removing duplicates and inserting empty strings in JavaScript
- How to read and write unicode (UTF-8) files in Python?
- UTF-8 Validation in C++
- Convert Unicode to UTF-8 in Java
- Convert UTF-8 to Unicode in Java
- How to convert an MySQL database characterset and collation to UTF-8?
- How to deal with floating point number precision in JavaScript?
- How to convert wrongly encoded data to UTF-8 in MySQL?
- How to convert byte literals to python strings?
- Convert String to UTF-8 bytes in Java
- Convert ASCII TO UTF-8 Encoding in PHP?
- How can I check JavaScript arrays for empty strings?

Advertisements