views:

45

answers:

1

The object is to find sets such as <!-- content:start -->some content here<!-- content:stop --> and process each one to put it into an array, but every time it find no matches and echos my die statement without printing any matches out. This is the current function that is being executed.

function boom($data) {
    $number = preg_match_all("/(<!-- ([\w]+):start -->)(.*?)(<!-- \\2:stop -->)/", $data, $matches, PREG_SET_ORDER);
    if ($number == 0) $data['content'] = $data;
    //else unset($data);
    foreach ($matches as $item) print_r($item)."\n\n"; // $data[$item[2]] = explode("<!-- breaker -->", $item[3]);
    die("<code>".str_replace("\n", "<br />", htmlentities($data))."</code>");
    return $data;
}

You can see what is being outputted here.

+1  A: 

If your text goes on multiple lines, just add the /s modifier to your pattern (to make . match newlines).

kemp
Isn't the entire piece `(<!-- ([\w]+):start -->)` considered the first match and the `([\w]+)` inside of it the second match?
animuson
Added correct pattern
kemp
Hmm, one letter makes all the difference, thanks!
animuson