<?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; match ereg_replace</title>
	<atom:link href="http://newsourcemedia.com/blog/tag/match-ereg_replace/feed/" rel="self" type="application/rss+xml" />
	<link>http://newsourcemedia.com/blog</link>
	<description>Focused on Interactive Design, Development and Marketing</description>
	<lastBuildDate>Sun, 09 May 2010 02:35:53 +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>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 code is below:

&#60;?
$var = 'abcdef [...]]]></description>
			<content:encoded><![CDATA[<p>How to replace only the first occurrence of a string in php.</p>
<p><span id="more-172"></span></p>
<p>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.</p>
<p>The code is below:<br />
<code><br />
&lt;?<br />
$var = 'abcdef abcdef abcdef';<br />
// pattern, replacement, string, limit<br />
echo preg_replace('/abc/', '123', $var, 1); // outputs '123def abcdef abcdef'<br />
?&gt; </code></p>
<p>Just incase you wanted to still match all occurrences, just use the php       function erag_replace.<br />
The code is below:</p>
<p><code><br />
&lt;?<br />
$var = 'abcdef abcdef abcdef';<br />
// pattern, replacement, string<br />
echo ereg_replace('abc', '123', $var); // outputs '123def 123def 123def'<br />
?&gt; </code></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://newsourcemedia.com/blog/flash-string-search-replace-using-prototype/" rel="bookmark">Flash string search replace using prototype</a></li><li><a href="http://newsourcemedia.com/blog/php-remove-last-character/" rel="bookmark">PHP Remove last character from string</a></li><li><a href="http://newsourcemedia.com/blog/php-validation-numbers-only-from/" rel="bookmark">PHP Validation Numbers Only From</a></li><li><a href="http://newsourcemedia.com/blog/php-remove-non-alphanumeric-characters/" rel="bookmark">Php Remove Non-Alphanumeric Characters</a></li><li><a href="http://newsourcemedia.com/blog/php-strip-remove-white-space-from-end-of-string/" rel="bookmark">PHP strip remove white space from end of string</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/php-replace-only-first-occurrence-of-a-string-match/feed/</wfw:commentRss>
		<slash:comments>4</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! -->