Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down