Here is another solution for you
$str = "{Vimeo}123456789{/Vimeo}"; preg_match("/\{(\w+)\}(.+?)\{\/\\1\}/", $str, $matches); printf("tag: %s, body: %s", $matches[1], $matches[2]);
Exit
tag: Vimeo, body: 123456789
Or you could build it as a function
function getTagValues($tag, $str) { $re = sprintf("/\{(%s)\}(.+?)\{\/\\1\}/", preg_quote($tag)); preg_match_all($re, $str, $matches); return $matches[2]; } $str = "{Vimeo}123456789{/Vimeo} and {Vimeo}123{/Vimeo}"; var_dump(getTagValues("Vimeo", $str));
Exit
array(2) { [0]=> string(9) "123456789" [1]=> string(3) "123" }
source share