- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
$str = '
#chapter 1: title 1
content chapter 1 line 1
content chapter 1 line 2
content chapter 1 line 3
content chapter 1 line 4
#chapter 2: title 2
content chapter 2 line 1
';
preg_match_all('/#Chapter\h+\d+:\h+title\h+\d+\K(?:\R(?!#chapter).*)*/i',$str, $match);
print_r($match[0]);