Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

preg_match(): Compilation failed: UTF-8 error: byte 2 top bits not 0x80 at offset 2

Working on a laravel project I recieved When running a route with this code I didn’t write:

if(preg_match('/([ΓΑΒΓΔΕΖΗΘΙΚ])|ΣΤ|fu|ΚΑ|ΚΒ\w+/u', $char)){
   return true;
}
return false;

For exapmple whe you give the Γ character you will get the error

preg_match(): Compilation failed: UTF-8 error: byte 2 top bits not 0x80 at offset 2

on php 8.1.9 and working on laravel. the same code works fine from tinker even when passing non english characters. What is the problem

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

>Solution :

The u flag in your expression means UTF-8. You are using Windows 1253, which is not UTF-8.

The best fix is to switch to UTF-8. Click on "Windows 1253", select "Save with encoding" and pick "UTF-8". Laravel and any contemporary web application are designed around UTF-8.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading