<?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>PHP Code</title>
	<atom:link href="http://www.phpcode.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpcode.net</link>
	<description>PHP Codes &#124; PHP Code Snippets &#124; PHP Programming Help</description>
	<lastBuildDate>Fri, 11 Nov 2011 07:22:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Regular Expressions</title>
		<link>http://www.phpcode.net/php/regular-expressions/</link>
		<comments>http://www.phpcode.net/php/regular-expressions/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 07:18:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.phpcode.net/?p=724</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 &#60;?php $text = &#34;Hello World&#34;; if ( preg_match( &#34;/r.*?d/&#34;, $text, $array ) ) { print &#34;&#60;pre&#62;\n&#34;; print_r( $array ); print &#34;&#60;/pre&#62;\n&#34;; } ?&#62; Output : Array ( [0] => rld ) Get an IP address 1 2 3 4 5 [...]]]></description>
			<content:encoded><![CDATA[<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre>
<pre>&lt;?php
$text = &quot;Hello World&quot;;
if ( preg_match( &quot;/r.*?d/&quot;, $text, $array ) ) {
  print &quot;&lt;pre&gt;\n&quot;;
  print_r( $array );
  print &quot;&lt;/pre&gt;\n&quot;;
}
?&gt;</pre>
</div>
<p>Output :<br />
Array<br />
(<br />
    [0] => rld<br />
)</p>
<p>Get an IP address</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre>
<pre>&lt;?php
$test = &quot;126.122.95.52&quot;;
if ( preg_match( &quot;/(\d+)\.(\d+)\.(\d+)\.(\d+)/&quot;, $test, $arr ) ) {
  print &quot;&lt;pre&gt;\n&quot;;
  print_r( $arr );
  print &quot;&lt;/pre&gt;\n&quot;;
}
?&gt;</pre>
</div>
<p>Output :<br />
Array<br />
(<br />
    [0] => 126.122.95.52<br />
    [1] => 126<br />
    [2] => 122<br />
    [3] => 95<br />
    [4] => 52<br />
)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpcode.net/php/regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8216;Array&#8217; Example</title>
		<link>http://www.phpcode.net/php/array-example/</link>
		<comments>http://www.phpcode.net/php/array-example/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 11:46:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.phpcode.net/?p=714</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 &#60;?php $arr = array(&#039;one&#039;, 2, &#039;three&#039;); $arr[] = &#039;the fourth element&#039;; echo $arr[3].&#34;&#60;br&#62;&#34;; echo $arr[1]; ?&#62; Output : the fourth element 2 Array indexing 1 2 3 4 5 6 7 8 9 10 11 12 13 &#60;?php $arr1 = array( &#34;Jan &#34;, &#34;Feb [...]]]></description>
			<content:encoded><![CDATA[<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
</pre>
<pre>&lt;?php
$arr = array(&#039;one&#039;, 2, &#039;three&#039;);
$arr[] = &#039;the fourth element&#039;;
echo $arr[3].&quot;&lt;br&gt;&quot;;
echo $arr[1];
?&gt;</pre>
</div>
<p>Output :<br />
the fourth element<br />
2</p>
<p>Array indexing</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
</pre>
<pre>&lt;?php
  $arr1 = array( &quot;Jan &quot;, &quot;Feb &quot;, &quot;Mar &quot; );
  $arr2 = array( &quot;11 &quot;, &quot;12 &quot;, &quot;13 &quot; );
  $arr3 = array( &quot;2001&quot;, &quot;2002&quot;, &quot;2003&quot; );

  echo( $arr1[1] . $arr2[0] . $arr3[1] );
?&gt;</pre>
</div>
<p>Output :<br />
Feb 11 2002</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
</pre>
<pre>&lt;?php
  $arr[0] = 32;
  $arr[1] = 52.15;
  $arr[2] = $arr[0] + $arr[1];

  echo &quot;Result = &quot;.&quot;$arr[0] + $arr[1] = $arr[2]&quot;;
 ?&gt;</pre>
</div>
<p>Output :<br />
Result = 32 + 52.15 = 84.15</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre>
<pre>&lt;?php
$num[&#039;A&#039;] = 12;
$num[&#039;A&#039;]++;
$num[&#039;B&#039;] = 3;

$num[&#039;total&#039;] = $num[&#039;A&#039;] + $num[&#039;B&#039;];
if ($num[&#039;total&#039;] &gt; 15) {
    print &quot;Greater Than 15.&lt;br&gt;&quot;;
}
print &#039;Number is : &#039; . $num[&#039;A&#039;];
?&gt;</pre>
</div>
<p>Output :<br />
Greater Than 15.<br />
Number is : 13</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre>
<pre>&lt;?php
     $arr[] = &quot;PHP&quot;;
     $arr[] = &quot;C&quot;;
     $arr[] = &quot;C++&quot;;
     $arr[] = &quot;Java&quot;;
     $arr[] = &quot;Perl&quot;;
     $arr[] = &quot;Python&quot;;
     $arr[] = &quot;Ruby&quot;;

     foreach($arr as $lang)
     {
          if(!strcmp($lang, &quot;PHP&quot;)){
               print(&quot;&lt;b&gt;&quot; . $lang . &quot;&lt;/b&gt; &lt;br /&gt;&quot;);
          }else{
               print($lang . &quot; &lt;br /&gt;&quot;);
          }
     }
?&gt;</pre>
</div>
<p>Output :<br />
PHP<br />
C<br />
C++<br />
Java<br />
Perl<br />
Python<br />
Ruby </p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpcode.net/php/array-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using this pointer</title>
		<link>http://www.phpcode.net/php/this-pointer/</link>
		<comments>http://www.phpcode.net/php/this-pointer/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 11:16:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.phpcode.net/?p=712</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 &#60;?php class Cat { var $age; function Cat($new_age){ $this-&#62;age = $new_age; } function Birthday( ){ $this-&#62;age++; } } $a = new Cat(1); [...]]]></description>
			<content:encoded><![CDATA[<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre>
<pre>&lt;?php
class Cat {
    var $age;
    function Cat($new_age){
        $this-&gt;age = $new_age;
    }
    function Birthday(  ){
        $this-&gt;age++;
    }
}

$a = new Cat(1);
echo &quot;Age is $a-&gt;age &lt;br /&gt;&quot;;
echo &quot;Birthday&lt;br/&gt;&quot;;

$a-&gt;Birthday(  );
echo &quot;Age is $a-&gt;age &lt;br /&gt;&quot;;
?&gt;</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.phpcode.net/php/this-pointer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Class with a Constructor</title>
		<link>http://www.phpcode.net/php/a-class-with-a-constructor/</link>
		<comments>http://www.phpcode.net/php/a-class-with-a-constructor/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 10:28:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.phpcode.net/?p=701</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 &#60;?php class Item { var $name; function Item( $name=&#34;&#34;) { $this-&#62;name = $name; } function setName( $n) { $this-&#62;name = [...]]]></description>
			<content:encoded><![CDATA[<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
</pre>
<pre>&lt;?php
 class Item {
   var $name;

   function Item( $name=&quot;&quot;) {
     $this-&gt;name = $name;
   }

   function setName( $n) {
     $this-&gt;name = $n;
   }

   function getName () {
     return $this-&gt;name;
   }
 }

 $item = new Item(&quot;5&quot;);
 print $item-&gt;getName ();
?&gt;</pre>
</div>
<p>Output :<br />
5</p>
<p>Invoking parent constructors</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
</pre>
<pre>&lt;?php
class Staff
{
    function __construct()
    {
        echo &quot;&lt;p&gt;Staff constructor called!&lt;/p&gt;&quot;;
    }
}

class Manager extends Staff
{
    function __construct()
    {
        parent::__construct();
        echo &quot;&lt;p&gt;Manager constructor called!&lt;/p&gt;&quot;;
    }
}

$employee = new Manager();
?&gt;</pre>
</div>
<p>Output :<br />
Staff constructor called!<br />
Manager constructor called!</p>
<p></p>
<p>Using Default Constructors</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre>
<pre>&lt;?php
class Dog {
    function __construct($name=&#039;No-name&#039;, $breed=&#039;breed unknown&#039;, $price = 23) {
        $this-&gt;name = $name;
        $this-&gt;breed = $breed;
        $this-&gt;price = $price;
    }
}
$aDog = new Dog();
$tweety = new Dog(&#039;A&#039;, &#039;a&#039;); 

printf(&quot;&lt;p&gt;%s is a %s and costs \$%.2f.&lt;/p&gt;\n&quot;,
$aDog-&gt;name, $aDog-&gt;breed, $aDog-&gt;price); 

$tweety-&gt;price = 34.56; 

printf(&quot;&lt;p&gt;%s is a %s and costs \$%.2f.&lt;/p&gt;\n&quot;,
$tweety-&gt;name, $tweety-&gt;breed, $tweety-&gt;price);
?&gt;</pre>
</div>
<p>Output :<br />
No-name is a breed unknown and costs $23.00.<br />
A is a a and costs $34.56.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpcode.net/php/a-class-with-a-constructor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8216;Session&#8217; Example</title>
		<link>http://www.phpcode.net/php/session-example/</link>
		<comments>http://www.phpcode.net/php/session-example/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 10:13:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.phpcode.net/?p=699</guid>
		<description><![CDATA[1 2 3 4 5 6 7 8 9 10 11 &#60;?php session_start(); ($_SESSION[&#039;count&#039;]) ? $_SESSION[&#039;count&#039;]++ : $_SESSION[&#039;count&#039;] = 1; ?&#62; You have been stay here &#60;?php echo( $_SESSION[&#039;count&#039;] ); ?&#62; times in this session]]></description>
			<content:encoded><![CDATA[<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
</pre>
<pre>&lt;?php
session_start();
($_SESSION[&#039;count&#039;]) ? $_SESSION[&#039;count&#039;]++ : $_SESSION[&#039;count&#039;] = 1;
?&gt;

 You have been stay here &lt;?php echo( $_SESSION[&#039;count&#039;] ); ?&gt; times in this session</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.phpcode.net/php/session-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Php &amp; javascript</title>
		<link>http://www.phpcode.net/javascript-code/php-javascript/</link>
		<comments>http://www.phpcode.net/javascript-code/php-javascript/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 06:24:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Javascript code]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.phpcode.net/?p=681</guid>
		<description><![CDATA[All the PHP code will execute on the server before the page is sent to the client, meaning all of the PHP calls have all been replaced by whatever text they returned once the JavaScript is able to execute. 1 2 3 4 5 &#60;script&#62; document.write(&#34;&#60;?php echo &#039;hello!&#039;; ?&#62;&#34;); &#60;/script&#62; 1 2 3 4 5 [...]]]></description>
			<content:encoded><![CDATA[<p>All the PHP code will execute on the server before the page is sent to the client, meaning all of the PHP calls have all been replaced by whatever text they returned once the JavaScript is able to execute.</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
</pre>
<pre>&lt;script&gt;
document.write(&quot;&lt;?php echo &#039;hello!&#039;; ?&gt;&quot;);
&lt;/script&gt;</pre>
</div>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
</pre>
<pre>&lt;?php
echo &quot;&lt;script language=\&quot;JavaScript\&quot;&gt;&quot;;
echo &quot;alert(\&quot;Hello World\&quot;);&quot;;
echo &quot;&lt;/script&gt;&quot;;
?&gt;</pre>
</div>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
</pre>
<pre>&lt;?php $phpvar=1; ?&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
jsvar = 3;
//Assign jsvar javascript variable value to php variable $phpvar
&#039;&lt;?php $phpvar=&quot;&lt;script&gt;document.write(jsvar)&lt;/script&gt;&quot;; ?&gt;&#039;;
&lt;/script&gt;
&lt;?php echo $phpvar; ?&gt;</pre>
</div>
<p>&#8216;Loop&#8217; Example</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
var counter = 0;
for(i=0;i&lt;10;i++){
counter++;
}
&lt;/script&gt;

&lt;?php
$phpvar= &quot;&lt;script&gt;document.write(counter)&lt;/script&gt;&quot;;
echo $phpvar;
?&gt;</pre>
</div>
<p>&#8216;Session&#8217; Example</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
</pre>
<pre>&lt;?php session_start(); $_SESSION[&#039;nume&#039;]=&#039;Sanat&#039;;?&gt;
&lt;!-- HTML code --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
alert(&quot;Welcome &lt;?php echo $_SESSION[&#039;nume&#039;]; ?&gt;&quot;);
&lt;/script&gt;</pre>
</div>
<p>&#8216;Switch&#8217; Example</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
function test(){
	document.getElementById(&quot;php_code&quot;).innerHTML=&quot;&lt;?php
		$w=&quot;do&quot;;
		switch($w){
		case &#039;do&#039;: echo &quot;You will be logged in?&quot;; break;
		case &#039;loguot&#039;: echo &quot;You will be logged out?&quot; ; break;
		}
	?&gt;&quot;;
}
&lt;/script&gt; 

&lt;a href=&quot;&quot; onclick=&quot;test(); return false;&quot;&gt; test &lt;/a&gt; &lt;br&gt;
&lt;span id=&quot;php_code&quot;&gt; &lt;/span&gt;</pre>
</div>
<p>Pass the value within url.</p>
<div class="fvch-code">
<pre class="fvch-line-numbers">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
</pre>
<pre>&lt;?php
    if(isset($_GET[action])){
	// Retrieve the GET parameters and executes the function
	  $funcName	 = $_GET[action];
	  $vars	  = $_GET[vars];
	  $funcName($vars);
	 } else if (isset($_POST[action])){
	  // Retrieve the POST parameters and executes the function
	  $funcName	 = $_POST[action];
	 $vars	  = $_POST[vars];
	 $funcName($vars);
	 } else {
		echo &quot;&lt;INPUT NAME=&#039;click_me&#039; TYPE=&#039;button&#039; ONCLICK=&#039;javascript:javaFunction()&#039; VALUE=&#039;Click Me&#039;&gt;&quot;;
	 }

   function phpFunction($v1){
	// makes an array from the passed variable
	// with explode you can make an array from string.
	$varArray = explode(&quot;,&quot;, $v1);	

	echo &quot;First Value: $varArray[0] &lt;BR&gt;&quot;;
	echo &quot;Second Value: $varArray[1]&lt;BR&gt;&quot;;
   }
  ?&gt; 

  &lt;SCRIPT language=&quot;javascript&quot;&gt;
   function javaFunction(){
	// In the varArray are all the variables you want to give with the function
	var varArray = new Array();
	varArray[0] = &quot;Hello&quot;;
	varArray[1] = &quot;World&quot;;

	// the url which you have to pass an action to the GET- or POST-variable
	var url=&quot;&lt;?php echo $_SERVER[PHP_SELF];?&gt;?action=phpFunction&amp;vars=&quot;+varArray;

	// Opens the url in the same window
	   window.open(url, &quot;_self&quot;);
	  }
  &lt;/SCRIPT&gt;</pre>
</div>
<p>Output :<br />
First Value: Hello<br />
Second Value: World</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phpcode.net/javascript-code/php-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

