Answer the question
In order to leave comments, you need to log in
Why regex101 and php return different result?
Hello. I have a string and I need to get everything that is after the first \n (this is not a line break, but a slash and a beech n). I do it like this
https://regex101.com/r/zZoGvw/1
but when I translate it into php, for some reason I get only the phone, and then no.
$z = "Запрос на доступ\nТелефон: 79991457764\nДанные: Останкин Ostoonekeen";
preg_match("/(?<=\\n).*/", $z, $user_info);
p($user_info);
/*Array
(
[0] => Телефон: 79991457764
)*/
Answer the question
In order to leave comments, you need to log in
explode("\n", $z, 2)[1]
or regular expression:
but it is slower
preg_match("/(?<=\n).*/s", $z, $user_info);
Because at you both lines different, and expressions.
In PHP, the string parser handles the backslash:
$z = "Запрос на доступ\nТелефон: 79991457764\nДанные: Останкин Ostoonekeen";
$r = "/(?<=\\n).*/";
var_dump($z);
var_dump($r);
/*
string(101) "Запрос на доступ
Телефон: 79991457764
Данные: Останкин Ostoonekeen"
string(11) "/(?<=\n).*/"
*/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question