I'm kind of staring blind on this one, trying to use preg_match_all to find texts placed in between hashes
##START of the text##
the text <b>starts</b> here etc
##END of the the text##
##START of the text 2##
Other version stringtext <b>starts</b> here etc
##END of the the text 2##
whatever I try, one time I get of the text
and other time only between hashes, can anybody help me with the regex?
$string = '##START of the text##
the text <b>starts</b> here etc
##END of the the text##
##START of the text 2##
Other version stringtext <b>starts</b> here etc
##END of the the text 2##';
preg_match_all('/##START.+?##[
](.+?)##END/s', $string, $matches);
// look for any characters between ##START and ##END, 's' will make it match newlines as well
print_r($matches[1]);
Will output:
Array
(
[0] => the text <b>starts</b> here etc
[1] => Other version stringtext <b>starts</b> here etc
)
I'm not so good with regex but here is my solution, i'm not matching lines starts with a hash,^ is for line-start, (?!#) is negative lookahead looking for # character, m modifier for multi-line.
$string = <<<EOD
##START of the text##
the text <b>starts</b> here etc
##END of the the text##
##START of the text 2##
Other version stringtext <b>starts</b> here etc
##END of the the text 2##
EOD;
preg_match_all('~^(?!#).*~m',$string,$match);
echo "<pre>";
print_r($match);
as i said i'm new to regex so an expert warn me if i'm wrong.
$str = '##START of the text##
the text <b>starts</b> here etc
##END of the the text##
##START of the text 2##
Other version stringtext <b>starts</b> here etc
##END of the the text 2##';
preg_match_all( '~##(.+)##~', $str, $matches );
print_r( $matches ) yield to :
Array ( [0] => START of the text [1] => END of the the text [2] => START of the text 2 [3] => END of the the text 2 )