<?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; functions</title>
	<atom:link href="http://newsourcemedia.com/blog/tag/functions/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>
		<item>
		<title>PHP Lesson 3 &#8211; Creating Functions</title>
		<link>http://newsourcemedia.com/blog/php-lesson-3-creating-functions/</link>
		<comments>http://newsourcemedia.com/blog/php-lesson-3-creating-functions/#comments</comments>
		<pubDate>Mon, 02 May 2005 00:22:11 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Beginner]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[create]]></category>
		<category><![CDATA[creating functions.]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[lesson]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://newsourcemedia.com/blog/2005/05/01/php-lesson-3-creating-functions/</guid>
		<description><![CDATA[How to create Functions in PHP and also how to Pass Variables to Functions. Introduction: You will need to have a PHP web server for this tutorial. We recommend SimpleHost.com for only $7.50 with Unlimited Disk Space, Subdomains, and Emails &#8230; <a href="http://newsourcemedia.com/blog/php-lesson-3-creating-functions/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[How to create Functions in PHP and also how to Pass Variables to Functions.
<span id="more-201"></span>
<span class="contitle">Introduction:</span>

You will need to have a PHP web server for this tutorial. We recommend <a href="http://www.simplehost.com/cgi/clickthru.cgi?id=alexmcleaniii">SimpleHost.com</a> for only $7.50 with Unlimited Disk Space, Subdomains, and Emails Accounts.

PHP has hundreds of predefined  functions (maybe thousands). This tutorial gives examples  on how to create your own php functions. There are two rules  I would like to share with you before we start.

<span class="contitle">Rule 1: </span>
Make sure your new function name does not exhist. You can  check PHP.net for a complete list of PHP predefined functions.

<span class="contitle">Rule 2: </span>
Do not declare/define the same function more than once inside the same file. You will get an error.

OK, let's create our first function. This function will display  a text advertisement. We will call this function ads().
<p class="contitle">Source Code</p>

<p class="sourceCODE">&lt;?php
// first define the function
function ads()
{
echo "Visit NewSourceMedia.com for free tutorials";
}
// now call the function ads() like so
ads();
?&gt;

Now you can display the same ad however many times you  want just by calling the function ads().
<p class="contitle">Passing Values to Functions:</p>

Let's say we want to randomly display three ads. We  could do this by placing three text ads inside our ads()  function and then passing a random value to it, to indicate  which ad to display. We can do this by using a parameter  variable inside the function. For example $n will be the  variable and this is how it is placed inside our ads function  like so "ads($n)". This variable holds a copy  of the value passed to it.

Now we need to set $n to a random number between 1 and  3. We can do this by using one of PHP pre-defined functions  called rand(). If you want a random number between 1 and  3 (inclusive), for example, use "rand (1, 3)".  To make this a little more clear, view the code below:
<p class="contitle">Source Code</p>
<p class="sourceCODE">&lt;?php</p>

// first define the function

function ads($n)
{

$a = "http://newsourcemedia.com";

if($n == 1)
echo "&lt;a href='$a'&gt;Visit NewSourceMedia.com for  free tutorials&lt;/a&gt;";

if($n == 2)
echo "&lt;a href='$a'&gt;NewSourceMedia.com for PHP  and much more!&lt;/a&gt;";

if($n == 3)
echo "&lt;a href='$a'&gt;PHP is Number One!&lt;/a&gt;"

} // end of function
<p class="sourceCODE">// define the random value for $n
$n = rand (1, 3);

// now call the function ads() with the value $n
ads($n);

?&gt;]]></content:encoded>
			<wfw:commentRss>http://newsourcemedia.com/blog/php-lesson-3-creating-functions/feed/</wfw:commentRss>
		<slash:comments>0</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! -->
