You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The reason will be displayed to describe this comment to others. Learn more.
Which is why the preg_replace is better than the str_replace (And I tested that it'll work with comment lines anywhere within a ini file. (The code as posted in this commit shows str_replace whereas bleeding edge plugin is using preg_replace)
since it only changes the first occurrence of the # to a ;
While mine will parse it correctly as
Array
(
[test] => testLine
[line2] => line2
)
Since it discards any line that begins with #
Not a real issue with unRaid, but if you're going to do it, you might as well do it right. All you need to do is add the m modifier to process the ini as separate lines and you can keep the comments if you choose
ca7c521
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what happens if one of the entries happens to contain a # symbol?
Better to use
function my_parse_ini_file($file,$mode=false,$scanner_mode=INI_SCANNER_NORMAL) {
return parse_ini_string(preg_replace('/^#.*\n/m', "", @file_get_contents($file)),$mode,$scanner_mode);
}
This only removes lines that start with a #
ca7c521
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ca7c521
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which is why the preg_replace is better than the str_replace (And I tested that it'll work with comment lines anywhere within a ini file. (The code as posted in this commit shows str_replace whereas bleeding edge plugin is using preg_replace)
ca7c521
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was initial code, later changed to preg_replace just to avoid what you describe above.
The my_ functions in Helpers replace the '#' for ';' but do not remove the comment line, which IMHO is neater.
ca7c521
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My version is actually better though
On an ini file like this:
this is a comment
test="testLine"
comment2="blah"
line2="line2"
Your version will parse it as
Array
(
[test] => testLine
[#comment2] => blah
[line2] => line2
)
since it only changes the first occurrence of the # to a ;
While mine will parse it correctly as
Array
(
[test] => testLine
[line2] => line2
)
Since it discards any line that begins with #
Not a real issue with unRaid, but if you're going to do it, you might as well do it right. All you need to do is add the m modifier to process the ini as separate lines and you can keep the comments if you choose