<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments for Mach13</title>
	<atom:link href="http://mach13.com/comments/feed" rel="self" type="application/rss+xml" />
	<link>http://mach13.com</link>
	<description>Internet Solutions</description>
	<pubDate>Wed, 10 Mar 2010 08:09:59 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by someone</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-637</link>
		<dc:creator>someone</dc:creator>
		<pubDate>Sat, 11 Apr 2009 16:13:27 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-637</guid>
		<description>nice, but whats the licence?</description>
		<content:encoded><![CDATA[<p>nice, but whats the licence?</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by bitMaster</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-632</link>
		<dc:creator>bitMaster</dc:creator>
		<pubDate>Fri, 13 Mar 2009 14:47:14 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-632</guid>
		<description>Excellent piece of code!

I made some changes to suit my needs, here's what's come out of it... it's slightly verbose, I thought of leaving it as is for anyone to better inspect... it handles multiline the smarty way (with triple quotes), as the code you provided would not work with conditions like the following:

var = "blabla
This cose is gonna "break"
because of the quote on line end"

My version goes single line with both single and double quotes, and implements the multiline like this:

var = """
This is a smarty-like multiline variable
"""

I didn't implement delimiter escaping, but at this point it would be trivial.

Here it goes:

function parseDataFile($pFile) {
		$aResult  =
		$aMatches = array();
	
		$a = &#38;$aResult;
		$s = '\s*([[:alnum:]_\- \*]+?)\s*';
	
		$RX	= '';

		$RX .=	'[\s\n]*';													// Any space and empty lines, and discard them
		$RX .=	'(?:';
		$RX .=		'(?:\[\s*(?P[^\n]+?)\s*\])';					// if it's a section, match it as "section"
		$RX .=		'&#124;';													// else...
		$RX .=		'(?:'; 													
		$RX .=			'(?P"?)(?P[^\n]+?)(?P=vardelim)';	// get the var name into "var" and it's delim (should there be one) into "vardelim"
		$RX .=			'\s*=\s*';											// skip the equal sign
		$RX .=			'(?:';												// two possible layouts:
		$RX .=				'(?s:"""\n(?P.*?)\n"""\n)';			// multiline, delimited by """, as in PHP ini files
		$RX .=				'&#124;';											// or...
		$RX .=				'((?P["\']?)(?P.*?)(?P=delim))';	// single line, catching the delimiter, which could be " or '
		$RX .=			')';
		$RX .=		')';
		$RX .=	')';
		$RX	.=	'\s*(?P;[^\n]*?)?$';								// Any comment afterwards gets fetched as "comment", just in case

		preg_match_all('#' . $RX . '#m', @file_get_contents($pFile), $aMatches, PREG_SET_ORDER);
	
		foreach ($aMatches as $aMatch) {
			if (empty($aMatch['section']))	$a[ $aMatch['var'] ] = ( !isset($aMatch['val']) ? $aMatch['multiline'] : $aMatch['val'] );
			else							$a = &#38;$aResult[ $aMatch['section'] ];
		}
	
		return $aResult;
	}


Any run against test-cases is very welcome, would save me debug time ;)

Cya!</description>
		<content:encoded><![CDATA[<p>Excellent piece of code!</p>
<p>I made some changes to suit my needs, here&#8217;s what&#8217;s come out of it&#8230; it&#8217;s slightly verbose, I thought of leaving it as is for anyone to better inspect&#8230; it handles multiline the smarty way (with triple quotes), as the code you provided would not work with conditions like the following:</p>
<p>var = &#8220;blabla<br />
This cose is gonna &#8220;break&#8221;<br />
because of the quote on line end&#8221;</p>
<p>My version goes single line with both single and double quotes, and implements the multiline like this:</p>
<p>var = &#8220;&#8221;"<br />
This is a smarty-like multiline variable<br />
&#8220;&#8221;"</p>
<p>I didn&#8217;t implement delimiter escaping, but at this point it would be trivial.</p>
<p>Here it goes:</p>
<p>function parseDataFile($pFile) {<br />
		$aResult  =<br />
		$aMatches = array();</p>
<p>		$a = &amp;$aResult;<br />
		$s = &#8216;\s*([[:alnum:]_\- \*]+?)\s*&#8217;;</p>
<p>		$RX	= &#8221;;</p>
<p>		$RX .=	&#8216;[\s\n]*&#8217;;													// Any space and empty lines, and discard them<br />
		$RX .=	&#8216;(?:&#8217;;<br />
		$RX .=		&#8216;(?:\[\s*(?P[^\n]+?)\s*\])&#8217;;					// if it&#8217;s a section, match it as &#8220;section&#8221;<br />
		$RX .=		&#8216;|&#8217;;													// else&#8230;<br />
		$RX .=		&#8216;(?:&#8217;;<br />
		$RX .=			&#8216;(?P&#8221;?)(?P[^\n]+?)(?P=vardelim)&#8217;;	// get the var name into &#8220;var&#8221; and it&#8217;s delim (should there be one) into &#8220;vardelim&#8221;<br />
		$RX .=			&#8216;\s*=\s*&#8217;;											// skip the equal sign<br />
		$RX .=			&#8216;(?:&#8217;;												// two possible layouts:<br />
		$RX .=				&#8216;(?s:&#8221;"&#8221;\n(?P.*?)\n&#8221;"&#8221;\n)&#8217;;			// multiline, delimited by &#8220;&#8221;", as in PHP ini files<br />
		$RX .=				&#8216;|&#8217;;											// or&#8230;<br />
		$RX .=				&#8216;((?P["\']?)(?P.*?)(?P=delim))&#8217;;	// single line, catching the delimiter, which could be &#8221; or &#8216;<br />
		$RX .=			&#8216;)&#8217;;<br />
		$RX .=		&#8216;)&#8217;;<br />
		$RX .=	&#8216;)&#8217;;<br />
		$RX	.=	&#8216;\s*(?P;[^\n]*?)?$&#8217;;								// Any comment afterwards gets fetched as &#8220;comment&#8221;, just in case</p>
<p>		preg_match_all(&#8217;#&#8217; . $RX . &#8216;#m&#8217;, @file_get_contents($pFile), $aMatches, PREG_SET_ORDER);</p>
<p>		foreach ($aMatches as $aMatch) {<br />
			if (empty($aMatch['section']))	$a[ $aMatch['var'] ] = ( !isset($aMatch['val']) ? $aMatch['multiline'] : $aMatch['val'] );<br />
			else							$a = &amp;$aResult[ $aMatch['section'] ];<br />
		}</p>
<p>		return $aResult;<br />
	}</p>
<p>Any run against test-cases is very welcome, would save me debug time <img src='http://mach13.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Cya!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by Michael</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-631</link>
		<dc:creator>Michael</dc:creator>
		<pubDate>Sat, 07 Mar 2009 17:12:06 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-631</guid>
		<description>How simple and concise!  I love it.

I needed it to handle Smarty-style multi-line values, like so:

longtext="""
this is a bunch of text
"""

I thought it would be easy to add an additional processing block in the middle.  This is what I added:

&#124;(("?)'.$s.'\\5\s*=\s*(""")(.*?)""")

between the two existing blocks in the (&#124;) section. I figured it would capture the multi-line values while leaving alone the standard single-quote values. Sadly, I am but a young padawan to your Jedi master regex skills, and my change killed normal single-quote handling.  Sigh.</description>
		<content:encoded><![CDATA[<p>How simple and concise!  I love it.</p>
<p>I needed it to handle Smarty-style multi-line values, like so:</p>
<p>longtext=&#8221;"&#8221;<br />
this is a bunch of text<br />
&#8220;&#8221;"</p>
<p>I thought it would be easy to add an additional processing block in the middle.  This is what I added:</p>
<p>|((&#8221;?)&#8217;.$s.&#8217;\\5\s*=\s*(&#8221;"&#8221;)(.*?)&#8221;"&#8221;)</p>
<p>between the two existing blocks in the (|) section. I figured it would capture the multi-line values while leaving alone the standard single-quote values. Sadly, I am but a young padawan to your Jedi master regex skills, and my change killed normal single-quote handling.  Sigh.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by Johnson</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-23</link>
		<dc:creator>Johnson</dc:creator>
		<pubDate>Wed, 18 Feb 2009 06:32:00 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-23</guid>
		<description>Good. It works well after your update.
Thanks.</description>
		<content:encoded><![CDATA[<p>Good. It works well after your update.<br />
Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by admin</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-22</link>
		<dc:creator>admin</dc:creator>
		<pubDate>Mon, 16 Feb 2009 09:14:13 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-22</guid>
		<description>You are right, Johnson

The PHP function "empty" considers that the string "0" is empty.

The line "if (!empty($aMatch[8]))"
has to be changed to : "if (empty($aMatch[2]))"
for safer Section detection.

The code above has been updated

Thanks</description>
		<content:encoded><![CDATA[<p>You are right, Johnson</p>
<p>The PHP function &#8220;empty&#8221; considers that the string &#8220;0&#8243; is empty.</p>
<p>The line &#8220;if (!empty($aMatch[8]))&#8221;<br />
has to be changed to : &#8220;if (empty($aMatch[2]))&#8221;<br />
for safer Section detection.</p>
<p>The code above has been updated</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by Johnson</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-21</link>
		<dc:creator>Johnson</dc:creator>
		<pubDate>Mon, 16 Feb 2009 05:15:59 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-21</guid>
		<description>It seems it has a problem to parse the value of key is 0. For example:
aa1 = bbb
aa2 = 0      ; Error
aa3 = "bbb"</description>
		<content:encoded><![CDATA[<p>It seems it has a problem to parse the value of key is 0. For example:<br />
aa1 = bbb<br />
aa2 = 0      ; Error<br />
aa3 = &#8220;bbb&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by Tobi</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-8</link>
		<dc:creator>Tobi</dc:creator>
		<pubDate>Fri, 06 Feb 2009 07:24:53 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-8</guid>
		<description>Oh jesus, YOU are god.... thanx</description>
		<content:encoded><![CDATA[<p>Oh jesus, YOU are god&#8230;. thanx</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by Steve</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-3</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Tue, 03 Feb 2009 13:50:56 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-3</guid>
		<description>Exactly what I was looking for, thank you very much!

BTW: I added some \,\? etc. to the $s= regex, so the key can hold commas, question marks, dots as well - however, I did not take the time to analyze the regex, just put it somewhere after the alnum part and it worked ;)</description>
		<content:encoded><![CDATA[<p>Exactly what I was looking for, thank you very much!</p>
<p>BTW: I added some \,\? etc. to the $s= regex, so the key can hold commas, question marks, dots as well - however, I did not take the time to analyze the regex, just put it somewhere after the alnum part and it worked <img src='http://mach13.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Loose and multiline parse_ini_file function in Php by Sergio</title>
		<link>http://mach13.com/loose-and-multiline-parse_ini_file-function-in-php/comment-page-1#comment-2</link>
		<dc:creator>Sergio</dc:creator>
		<pubDate>Tue, 03 Feb 2009 00:46:25 +0000</pubDate>
		<guid isPermaLink="false">http://mach13.com/?p=64#comment-2</guid>
		<description>Ah, just what I was looking for. ;)

Sit down, excellent!

Tnx a lot!</description>
		<content:encoded><![CDATA[<p>Ah, just what I was looking for. <img src='http://mach13.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Sit down, excellent!</p>
<p>Tnx a lot!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
