diff --git a/helper.php b/helper.php index 6818802..df0f5df 100644 --- a/helper.php +++ b/helper.php @@ -151,6 +151,25 @@ public static function loadContent($file) */ public static function prepareData($content, $opt) { + // Pattern explanation: + // / - Start delimiter + // ^ - Start of line (due to m-modifier) + // \s* - Match zero or more whitespace characters + // # - Match the literal hash symbol + // .* - Match any character until... + // (\R|$) - ...the next newline sequence (universal line break) OR the + // end of the string ($) to ensure the last line is caught. + // /m - End delimiter, with 'm' (multiline) modifier + $comment_pattern = '/^\s*#.*(\R|$)/m'; + + // This replaces lines starting with '#' (even with leading whitespace) + // with an empty string, effectively removing the line. + $content = preg_replace($comment_pattern, '', $content); + + // Remove any trailing empty lines that might have resulted from the replacement. + // Strictly speaking, this is not necessary but just adding it for safety. + $content = trim($content); + $data = []; // get the first row - it will define the structure