开发者

What am I doing wrong with preg_match_all?

开发者 https://www.devze.com 2022-12-19 04:58 出处:网络
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

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. Note: The content in between the start and end tags usually spa开发者_如何学Cns multiple lines.

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;
}


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

0

精彩评论

暂无评论...
验证码 换一张
取 消