- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$re = '/^\h*\\\\_+\\\\_\R((?:.*\R(?!\h*\\\\_+\\\\_).*)*)/m';
$str = '---
- ID: some random id
\\_______________________________\\_
HELLO
This is an example text.
I AM SECTION 1
\\_______________________________\\_
HELLO
This is an example text.
I AM SECTION 2
\\_______________________________\\_
HELLO
This is an example text.
I AM SECTION 3
\\_______________________________\\_
hello
this is example text here
and i am section 4';
preg_match_all($re, $str, $matches);
print_r($matches[1]);