-
-
Save cubespace/19ed1fed8ae400fb3a9c84fbb2236a95 to your computer and use it in GitHub Desktop.
Возврат подстроки, которая начинается с определенной строки и заканчивается определенной строкой без их включения в результат, preg_match
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$str = 'the result inside big string'; | |
preg_match("/(?<=the )(.*)(?= inside)/", $str, $result_arr); | |
echo $result_arr[0]; // result | |
/* | |
(?<=) - с чего начинается искомая строка | |
(?=) - чем заканчивается искомая строка | |
(.*) - искомая строка содержит любое количество любых символов | |
PS: хороший конструктор регулярных выражений - http://www.phpliveregex.com/ | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment