<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AkillesBlog &#187; RegEx</title>
	<atom:link href="http://blog.akilles.org/tag/regex/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.akilles.org</link>
	<description>Talk on programming, computers, electronics, web etc</description>
	<lastBuildDate>Sun, 13 Jun 2010 02:42:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>preg_replace in PHP with /e flag</title>
		<link>http://blog.akilles.org/2008/09/17/preg_replace-in-php-with-e-flag/</link>
		<comments>http://blog.akilles.org/2008/09/17/preg_replace-in-php-with-e-flag/#comments</comments>
		<pubDate>Wed, 17 Sep 2008 18:36:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[RegEx]]></category>

		<guid isPermaLink="false">http://blog.akilles.org/?p=65</guid>
		<description><![CDATA[The /e flag makes the (quoted) replacement string to be treated as PHP-code, so that one can make more complex regex-replacements in a one-liner.
An example: I want to search for a pattern in a string, and replace any occurences with an array element whose key/index equals the occurence.
Without the /e flag this wouldn&#8217;t be as [...]]]></description>
			<content:encoded><![CDATA[<p>The /e flag makes the (quoted) replacement string to be treated as PHP-code, so that one can make more complex regex-replacements in a one-liner.</p>
<p>An example: I want to search for a pattern in a string, and replace any occurences with an array element whose key/index equals the occurence.</p>
<p>Without the /e flag this wouldn&#8217;t be as easy, because this <strong>does not</strong> work;</p>
<pre name="code" class="php">

$pattern = '/\{(.*?)\}/i';
$outputline = preg_replace($pattern, $array[\\1], $inputline); //doesn't make any sense
</pre>
<p>With the /e flag, however, this works like a charm;</p>
<pre name="code" class="php">

$pattern = '/\{(.*?)\}/ei'; //note the /e flag
$outputline = preg_replace($pattern, '$array[\\1]', $inputline); //works with /e flag
</pre>
<p>This replaces occurences of $pattern in $inputline with $array[OccurenceOfPatternInInputline] and assigns the result to $outputline.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.akilles.org/2008/09/17/preg_replace-in-php-with-e-flag/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
