Remove russian letters from string in php

How can I remove all Russian letters from a string in PHP?
Or vice versa, I would save only.
English letters, spaces, numbers and all characters, such as! @ # $% ^ & * () {} ":?> <> ~ '"

How can I do this, thanks.

I understand, I replace all Russian crickets ### and then I substring from beginning to end.

$desc = preg_replace('/[-]+/iu','###', $desc); $start = strpos ($desc,'###'); $end =strrpos ($desc,"###"); if($start!==false) { $descStart = substr($desc,0,$start); $descEnd = substr($desc,$end+3); $desc = $descStart.$descEnd; } 
+4
source share
3 answers
 $string = '    Stackoverflow >!<'; var_dump(preg_replace('/[\x{0410}-\x{042F}]+.*[\x{0410}-\x{042F}]+/iu', '', $string)); 

The input string must be in Unicode, and the output must also be in Unicode

+3
source

The following regular expression will match the letters in the Cyrrilic script: http://regex101.com/r/sO0uB7 (an example based on the text of Andrey Vorobyov)

I think this is what you need.

I'm not sure if the i modifier is needed.

+2
source

My approach would be to transliterate the string in ASCII first (to save as much information as possible) and then remove the invalid characters:

 $url = iconv("utf-8", "us-ascii//TRANSLIT", $url); $url = strtolower($url); $url = preg_replace('~[^-a-z0-9_]+~', '', $url); 

You will need to extend the regular expression at the end so that it matches what you need.

0
source

All Articles