There is such data:
$pattern = "/статьи/администрирование/([0-9])+/([0-9])+/"; $string = "/статьи/администрирование/129/123/"; I need some kind of mechanism that could extract the numbers 129 and 123 from $string , with what $pattern can change, for example, if it will be like this:
$pattern = "/статьи/администрирование/([0-9])+/"; and $string is:
$string = "/статьи/администрирование/129/"; then you need to pull out the number 129.
I did this:
if(preg_match("~$pattern ~", $string ,$matches)){ echo "<pre>"; print_r($matches); echo "</pre>"; } But received in the $matches array is not what you need, namely:
Array ( [0] => /статьи/администрирование/129/123/ [1] => 9 [2] => 3 ) How to make it so in the array:
Array ([0] => / articles / administration / 129/123 / [1] => 129 [2] => 123)
+inside the parentheses make - teran([0-9])+with(\d+)and remove the space after the template variable in"~$pattern ~"- Lexx918