【发布时间】:2025-12-10 01:25:01
【问题描述】:
我正在尝试编写一些 PHP 来读取 CSS 文件,查找所有出现的 @group 注释及其行号。这是我目前所拥有的,但它返回的是字符数而不是行号。
$file = 'master.css';
$string = file_get_contents($file);
$matches = array();
preg_match_all('/\/\* @group.*?\*\//m', $string, $matches, PREG_OFFSET_CAPTURE);
list($capture, $offset) = $matches[0];
$line_number = substr_count(substr($string, 0, $offset), "\n") + 1;
echo '<pre>';
print_r($matches[0]);
echo '</pre>';
【问题讨论】: