<?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>NewSourceMedia Blog &#187; grep</title>
	<atom:link href="http://newsourcemedia.com/blog/tag/grep/feed/" rel="self" type="application/rss+xml" />
	<link>http://newsourcemedia.com/blog</link>
	<description>Focused on Interactive Design, Development and Marketing</description>
	<lastBuildDate>Fri, 30 Dec 2011 04:30:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>PHP replace only first occurrence of a string match.</title>
		<link>http://newsourcemedia.com/blog/php-replace-only-first-occurrence-of-a-string-match/</link>
		<comments>http://newsourcemedia.com/blog/php-replace-only-first-occurrence-of-a-string-match/#comments</comments>
		<pubDate>Tue, 30 Nov 1999 06:00:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[String Manipulation]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[match ereg_replace]]></category>
		<category><![CDATA[occurrences]]></category>
		<category><![CDATA[pattern.]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[replace]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/1969/12/31/php-replace-only-first-occurrence-of-a-string-match/</guid>
		<description><![CDATA[How to replace only the first occurrence of a string in php. Say you wanted to only replace the first occurrence of a string match instead of all occurrences You would use php preg_replace function to do the trick. The &#8230; <a href="http://newsourcemedia.com/blog/php-replace-only-first-occurrence-of-a-string-match/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[How to replace only the first occurrence of a string in php.

<span id="more-172"></span>

Say you wanted to only replace the       first occurrence of a string match instead of all occurrences You would       use php preg_replace function to do the trick.

The code is below:
<code>
&lt;?
$var = 'abcdef abcdef abcdef';
// pattern, replacement, string, limit
echo preg_replace('/abc/', '123', $var, 1); // outputs '123def abcdef abcdef'
?&gt; </code>

Just incase you wanted to still match all occurrences, just use the php       function erag_replace.
The code is below:

<code>
&lt;?
$var = 'abcdef abcdef abcdef';
// pattern, replacement, string
echo ereg_replace('abc', '123', $var); // outputs '123def 123def 123def'
?&gt; </code>]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/php-replace-only-first-occurrence-of-a-string-match/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
