V
V
Vitaly Khvan2017-06-20 09:22:53
Yii
Vitaly Khvan, 2017-06-20 09:22:53

Wrong encoding or wrong regular expression? How to fix?

I get the data using the GET method

$request = Yii::$app->request;
 $message = $request->get('message');

Further processing takes place using the preg_replace function:
$code = preg_replace ("/[^0-9\s]/","",$message);
$triger = preg_replace ("/[^a-zA-ZА-Яа-я\s]/","",$message);

and when you try to use it, the following signs appear:
click

Try text:
STOP KITCHEN

MK 1938

MK is displayed adequately, but nothing sensible comes out with the first sentence.
If possible, please explain what I'm doing wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2017-06-20
@xRites

Good morning.
Encoding.
Check encoding matches everywhere, convert everything to utf-8.
Also add the "u" modifier to the regular expression.

$triger = preg_replace ("/[^a-zA-ZА-Яа-я\s]/u","",$message);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question