Answer the question
In order to leave comments, you need to log in
Parse and get word between two characters, php?
Hello.
It is necessary from the text, get the city and phone number in the form (Moscow: +71234566789).
A solution has been found.
$text = explode("Москва", $text);
$text = explode("\n", $text[1]);
echo $text[0];
$text = explode("Питер: ", $text);
$text = explode("\n", $text[1]);
echo $text[0];
$text = explode("Москва: ", $text);
$text = explode("\n", $text[1]);
echo $text[0];
$pattern2 = "|Москва: (.+?) \n |is";
preg_match($pattern2, $text, $datee);
echo $datee;
Answer the question
In order to leave comments, you need to log in
Try like this:
$s = "Москва: +71234566789 Питер: +7111111111";
preg_match_all('/(Москва|Питер):\s*(\S+)/m', $s, $r);
foreach ($r[0] as $v) {
echo($v.'<br>');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question