E
E
EvgMul2016-10-08 02:47:28
PHP
EvgMul, 2016-10-08 02:47:28

How to leave only Cyrillic in a string?

Hello. I have the following problem. It is required to remove all characters from the string, except for spaces and Cyrillic. I do it like this:

$titleAttraction = "Красная площадь Red Square (Krasnaya ploshchad)";
$russianTitleAttraction = preg_replace("/[^а-я ]/", "" , $titleAttraction);
$russianTitleAttraction = trim($russianTitleAttraction);
echo $russianTitleAttraction;

Everything seems to be displayed correctly, but some characters are replaced by abbreviations in the form of a question mark , something like the following: If you display the original string on the screen, this does not happen. Please tell me what I'm doing wrong and how to fix it?
Thanks in advance to all who respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xmoonlight, 2016-10-08
@EvgMul

The file must be encoded in Unicode UTF-8 and in the regular expression /[^a-z ]/u

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question