- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$str = " \\begin{verbatim} dupa zbita \\end \\end{verbatim} I chuj!!! \\end{verbatim}";
preg_match_all('/(?s)\\\\begin\s*\{([a-z]*?\*?)\}(.*?)\\\\end\s*\{\1\}/', $str, $match);
print_r($match);