<?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>Developer Code book &#187; PHP</title> <atom:link href="http://wordpressapi.com/category/php/feed/" rel="self" type="application/rss+xml" /><link>http://wordpressapi.com</link> <description>Wordpressapi.com is focused on Wordpress API, wordpress news, wordpress themes, wordpress plugins, wordpress tips, wordpress tutorials, wordpress design wordpress templates, wordpress breaking news and web-development. We deliver useful information about wordpress,  wordpress latest trends and wordpress techniques, wordpress useful ideas, wordpress innovative approaches and wordpress tools. Social Media news blog covering cool new websites and social networks: Facebook, Google, Twitter, MySpace and YouTube.  The latest web technology news, via RSS daily.</description> <lastBuildDate>Thu, 09 Sep 2010 10:36:02 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>How to use mongodb with php</title><link>http://wordpressapi.com/2010/09/09/mongodb-php/</link> <comments>http://wordpressapi.com/2010/09/09/mongodb-php/#comments</comments> <pubDate>Thu, 09 Sep 2010 10:36:02 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[MySql]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[Server]]></category> <category><![CDATA[linux]]></category> <category><![CDATA[mongo]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=5265</guid> <description><![CDATA[If you want to use the mongodb with php then you need to install pecl libraries. Mongo extension is not bundled with PHP. For installing the Mongo use following URL: If you dont have pecl installed on your linux machine then use following command. # yum install php-pecl* then use following command # pecl install.....]]></description> <content:encoded><![CDATA[<div
id="_mcePaste"><img
class="alignnone size-full wp-image-5266" title="mongodb-and-php" src="http://wordpressapi.com/files/mongodb-and-php.jpg" alt="" width="493" height="227" /></div><div>If you want to use the mongodb with php then you need to install pecl libraries. Mongo extension is not bundled with PHP.</div><div
id="_mcePaste">For installing the Mongo use following URL:</div><div
id="_mcePaste">If you dont have pecl installed on your linux machine then use following command.</div><div
id="_mcePaste"># yum install php-pecl*</div><div
id="_mcePaste">then use following command</div><div
id="_mcePaste"># pecl install mongo</div><div
id="_mcePaste">Then open the php.ini file. if you are using the linux then use following command.</div><div
id="_mcePaste"># vim /etc/php.ini</div><div
id="_mcePaste"><pre class="brush: plain;">&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;## Add following lines, end of php.ini file ##&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;# MongoDB Driver&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;extension=mongo.so&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;</pre></div><div
id="_mcePaste">Restart the apache webserver using following command</div><div
id="_mcePaste"># /etc/init.d/httpd restart</div><div
id="_mcePaste">If Mongodb server is running then use can test your mongodb database using following code:</div><div
id="_mcePaste">Create the mongotest.php file</div><div
id="_mcePaste"><pre class="brush: plain;">&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;&lt;?php&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;// connect&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$m = new Mongo();&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;// select a database&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$db = $m-&gt;wordpress;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$collection = $db-&gt;wordpressapi;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;// add an element&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$obj = array( &quot;title&quot; =&gt; &quot;Sony this Good.\n&quot;, &quot;author&quot; =&gt; &quot;Wordpressapi.com&quot; );&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$collection-&gt;insert($obj);&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;// add another element, with a different &quot;shape&quot;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$obj = array( &quot;title&quot; =&gt; &quot;Wordpressapi.com&quot;, &quot;online&quot; =&gt; true );&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$collection-&gt;insert($obj);&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;// find everything in the collection&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$cursor = $collection-&gt;find();&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;// iterate through the results&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;foreach ($cursor as $obj) {&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;echo $obj[&quot;title&quot;] . &quot;\n&quot;;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;echo $obj[&quot;author&quot;] . &quot;\n&quot;;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;}&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;// disconnect&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;$m-&gt;close();&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;?&gt;&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;[/php]&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;If you open this file in browser then you can see the following words in browser:&lt;/div&gt;
&lt;div id=&quot;_mcePaste&quot;&gt;Sony this Good. WordPressapi.com Sony this Good. WordPressapi.com&lt;/div&gt;
If you want to use the mongodb with php then you need to install pecl libraries. Mongo extension is not bundled with PHP.
For installing the Mongo use following URL:
If you dont have pecl installed on your linux machine then use following command.# yum install php-pecl*
then use following command# pecl install mongo
Then open the php.ini file. if you are using the linux then use following command.
# vim /etc/php.ini
[code]## Add following lines, end of php.ini file ### MongoDB Driverextension=mongo.so</pre><p>Restart the apache webserver using following command<br
/> # /etc/init.d/httpd restart<br
/> If Mongodb server is running then use can test your mongodb database using following code:<br
/> Create the mongotest.php file[/code]&lt;?php<br
/> // connect$m = new Mongo();<br
/> // select a database$db = $m-&gt;wordpress;$collection = $db-&gt;wordpressapi;<br
/> // add an element$obj = array( &#8220;title&#8221; =&gt; &#8220;Sony this Good.\n&#8221;, &#8220;author&#8221; =&gt; &#8220;WordPressapi.com&#8221; );$collection-&gt;insert($obj);<br
/> // add another element, with a different &#8220;shape&#8221;$obj = array( &#8220;title&#8221; =&gt; &#8220;WordPressapi.com&#8221;, &#8220;online&#8221; =&gt; true );$collection-&gt;insert($obj);<br
/> // find everything in the collection$cursor = $collection-&gt;find();<br
/> // iterate through the resultsforeach ($cursor as $obj) {    echo $obj["title"] . &#8220;\n&#8221;;     echo $obj["author"] . &#8220;\n&#8221;;}<br
/> // disconnect$m-&gt;close();<br
/> ?&gt;<br
/> [/php]<br
/> If you open this file in browser then you can see the following words in browser:Sony this Good. WordPressapi.com Sony this Good. WordPressapi.com</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/09/09/mongodb-php/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Post message to another server through fopen and fsockopen in php</title><link>http://wordpressapi.com/2010/09/08/post-message-server-fopen-fsockopen-php/</link> <comments>http://wordpressapi.com/2010/09/08/post-message-server-fopen-fsockopen-php/#comments</comments> <pubDate>Wed, 08 Sep 2010 10:37:34 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[Web Service]]></category> <category><![CDATA[XML]]></category> <category><![CDATA[Server]]></category> <category><![CDATA[web service]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=5256</guid> <description><![CDATA[When this comes to sending data to server to server we need to post the data using web services. Many people want to use the curl php method but there are serious issues with that. So I recomond to use fopen function to post the message to server to server. You can use the following.....]]></description> <content:encoded><![CDATA[<p><img
class="alignnone size-full wp-image-5257" title="post-message-to-server" src="http://wordpressapi.com/files/post-message-to-server.jpeg" alt="" width="225" height="225" /><br
/> When this comes to sending data to server to server we need to post the data using web services.<br
/> Many people want to use the curl php method but there are serious issues with that.<br
/> So I recomond to use fopen function to post the message to server to server.</p><p>You can use the following code for post the message to another server using fopen and fsockopen</p><pre class="brush: php;">
    function post($host, $post_url,$port,$data) {
        $errno = 0;
        $errstr = '';

        $path = str_replace($host,'',$post_url); // IP of minor instance

        $header_variables = &quot;POST / HTTP/1.1\r\n&quot;;
        $header_variables .= &quot;Host: $host\r\n&quot;;
        $header_variables .= &quot;Connection: Close\r\n&quot;;
        $header_variables .= &quot;Content-Type: application/xml\r\n&quot;;
        $header_variables .= &quot;Content-Length: &quot; . strlen($data) . &quot;\r\n\r\n&quot;;

        // establish the connection and send the request
        $fp = fsockopen($host, $port, &amp;$errno, &amp;$errstr, 15);
        if ($fp) {
            stream_set_timeout($fp, 15);
            fputs($fp, $header_variables);
            fputs ($fp, $data); //data written
            fputs ($fp, &quot;\r\n&quot;); //request posted

            $response = stream_get_contents($fp);
            $info = stream_get_meta_data($fp);
            if (!$info['timed_out'] &amp;&amp; $fp) {
                //get response and everything is ok
            } else {
                trigger_error('Timed out for '.$post_url);
                exit();
            }

            fclose($fp); //close the file

        } else {
            trigger_error('Failed to open socket connection. ');
            exit();
        }
    }

[php]

using CURL function post message also possible for that you can use following code
[php]
&lt;?php

/* http://localhost/upload.php:
print_r($_POST);
print_r($_FILES);
*/

$ch = curl_init();

$data = array('name' =&gt; 'Foo', 'file' =&gt; '@/home/user/test.png');

curl_setopt($ch, CURLOPT_URL, 'http://localhost/upload.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
?&gt;
</pre>]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/09/08/post-message-server-fopen-fsockopen-php/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>how to make simple guestbook with php</title><link>http://wordpressapi.com/2010/06/26/simple-guestbook-php/</link> <comments>http://wordpressapi.com/2010/06/26/simple-guestbook-php/#comments</comments> <pubDate>Sat, 26 Jun 2010 13:00:55 +0000</pubDate> <dc:creator>Mahesh</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[php code]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=3647</guid> <description><![CDATA[Here&#8217;s a easy way to create guestbook with php. First you have to create database for it. If your database has been created add this table to database. CREATE TABLE IF NOT EXISTS `posts` ( `name` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, `website` varchar(100) NOT NULL, `message` text NOT NULL, `ip` varchar(25) NOT NULL,.....]]></description> <content:encoded><![CDATA[<p>Here&#8217;s a easy way to create guestbook with php.</p><p>First you have to create database for it. If your database has been created add this table to database.</p><pre class="brush: sql;">

 CREATE TABLE IF NOT EXISTS `posts` (

 `name` varchar(100) NOT NULL,

 `email` varchar(100) NOT NULL,

 `website` varchar(100) NOT NULL,

 `message` text NOT NULL,

 `ip` varchar(25) NOT NULL,

 `date` varchar(50) NOT NULL

 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
</pre><p><span
style="color: #808000">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span></p><p><span
style="font-size: large"><strong>Step 1: Creating A Form</strong></span></p><p>First we have to create a form. to do this use the following PHP code:</p><p><code><code>echo "&lt;form action='index.php?act=add' method='post'&gt;"</code></code></p><p>.&#8221;Name:<br
/> &lt;input type=&#8217;text&#8217; name=&#8217;name&#8217; size=&#8217;30&#8242; /&gt;<br
/> &#8221;</p><p>.&#8221;Email:<br
/> &lt;input type=&#8217;text&#8217; name=&#8217;email&#8217; size=&#8217;30&#8242; /&gt;<br
/> &#8221;</p><p>.&#8221;Website:<br
/> &lt;input type=&#8217;text&#8217; name=&#8217;website&#8217; size=&#8217;30&#8242; /&gt;<br
/> &#8221;</p><p>.&#8221;Message:<br
/> &lt;textarea cols=&#8217;30&#8242; rows=&#8217;8&#8242; name=&#8217;message&#8217;&gt;&lt;/textarea&gt;<br
/> &#8221;</p><p>.&#8221;&lt;input type=&#8217;submit&#8217; value=&#8217;Post&#8217; /&gt;&#8221;</p><p>.&#8221;&lt;/form&gt;&#8221;;</p><p><span
style="color: #808000">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span><br
/> <span
style="font-size: large"><strong>Step 2: Add Info To Database</strong></span></p><p>Now we have to add info to database. Do this using by this PHP code:</p><p><code><code><br
/> if($_GET['act'] == "add") </code></code></p><p><code><code>{ // If act is "add" like this file.php?act=add display the content</code></code></p><p>$sqlCon = mysql_connect(&#8220;localhost&#8221;, &#8221;root&#8221;, &#8221;bananaman&#8221;); // Connect to database</p><p>if($sqlCon == true){ // If connection has been made then..</p><p>$sqlSel = mysql_select_db(&#8220;guestbook&#8221;, $sqlCon); // Select a database</p><p>if($sqlSel == true)</p><p><code><code>{ // If database has been successfully selected gather info and post it</code></code></p><p>$name = addslashes(htmlspecialchars($_REQUEST['name'])); // Takes &#8221;name&#8221; field from the form</p><p>$email = addslashes(htmlspecialchars($_REQUEST['email'])); // Takes &#8221;email&#8221; field from the form</p><p>$website = addslashes(htmlspecialchars($_REQUEST['website'])); // Takes &#8221;website&#8221; field from the form</p><p>$message = addslashes(htmlspecialchars($_REQUEST['message'])); // Takes &#8221;message&#8221; field from the form</p><p>$ip = $_SERVER['REMOTE_ADDR']; // This takes user&#8217;s IP</p><p>$time = time(); // Get UNIX timestamp</p><p>// This will create a SQL query which inserts all that information into database</p><p>$sql = &#8221;INSERT INTO posts (name, email, website, message, ip)</p><p><code><code>VALUES ('".$name."', '".$email."', '".$website."', </code></code></p><p><code><code>'".$message."', '".$ip."', '".$time."')";</code></code></p><p>// This will process SQL query and performs inserting info to database</p><p>$query = mysql_query($sql);</p><p>if($query == true) { // If everything was correct ..</p><p>echo &#8221;Your post has been successfully posted!&#8221;; // Display a success message</p><p>}else { // But if there was something wrong ..</p><p>echo &#8221;There was something wrong.&#8221;; // Display a fail message</p><p>// As you can see I have commented</p><p>// mysql_error() function. It is because</p><p>// if you want to see what went wrong with</p><p>// your SQL query. Displaying it is not very</p><p>// good idea because it&#8217;s like a candy to</p><p>// hackers. So if you have fixed the problem</p><p>// make sure to add comment &#8221;//&#8221; in front of it</p><p>//echo mysql_error();</p><p>}</p><p>mysql_close($sqlCon); // Close connection to database</p><p>}else{</p><p>exit; // If database selection wasn&#8217;t a success close script</p><p>}</p><p>}else{</p><p>exit; // If connecting to database wasn&#8217;t a success close script</p><p>}</p><p>}</p><p><span
style="color: #808000">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span></p><p><span
style="font-size: large"><strong>Step 3: Displaying Posts</strong></span></p><p>Now posting part is done, now we&#8217;re going to display our posts.</p><p>Use this PHP code:</p><p><code><code>$sqlCon = mysql_connect("localhost", "root", "bananaman"); // Connect to database</code></code></p><p>if($sqlCon == true) { // If connecting was successful ..</p><p>$sqlSel = mysql_select_db(&#8220;guestbook&#8221;, $sqlCon); // select your database</p><p>if($sqlSel == true) { // If database selecting was successful then take info from it</p><p>// Select all records from database</p><p>$sql = &#8221;SELECT * FROM posts&#8221;;</p><p>// Process your selection</p><p>$query = mysql_query($sql);</p><p>// This creates a table which contains all info</p><p>// of your posts</p><p>while($info = mysql_fetch_array($query)) {</p><p>echo &#8221;&lt;table width=&#8217;300&#8242; border=&#8217;1&#8242;&gt;&#8221;</p><p>.&#8221;&lt;tr&gt;&#8221;</p><p>.&#8221;&lt;td&gt;Posted by: &lt;a href=&#8217;&#8221;.$info['website'].&#8221;&#8216;&gt;&#8221;.$info['name'].&#8221;&lt;/a&gt; (&lt;a href=&#8217;mailto:&#8221;.$info['email'].&#8221;&#8216;&gt;Email&lt;/a&gt;)&lt;/td&gt;&#8221;</p><p>.&#8221;&lt;td align=&#8217;right&#8217;&gt;&#8221;.date(&#8220;H:i j F Y&#8221;, $info['date']).&#8221;&lt;/td&gt;&#8221;</p><p>.&#8221;&lt;/tr&gt;&#8221;</p><p>.&#8221;&lt;tr&gt;&#8221;</p><p>.&#8221;&lt;td colspan=&#8217;2&#8242;&gt;&#8221;.$info['message'].&#8221;&lt;/td&gt;&#8221;</p><p>.&#8221;&lt;/tr&gt;&#8221;</p><p>.&#8221;&lt;/table&gt;&#8221;</p><p>.&#8221;<br
/> &#8220;;</p><p>}</p><p>mysql_close($sqlCon); // Close database connection</p><p>}else { // If database selection wasn&#8217;t successful ..</p><p>exit; // exit form the script</p><p>}</p><p>}else { // If connection to database wasn&#8217;t success ..</p><p>exit; // exit from your script</p><p>}</p><p><span
style="color: #808000">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span></p><p>And you are done with your script. It should look like this:</p><p><a
href="http://wordpressapi.com/files/simple-guestbook-with-php1.jpg"><img
class="alignnone size-full wp-image-3655" title="simple-guestbook-with php" src="http://wordpressapi.com/files/simple-guestbook-with-php1.jpg" alt="" width="325" height="415" /></a></p><p><span
style="color: #808000">~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</span></p><p>Thank you!</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/06/26/simple-guestbook-php/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>How to use memcached with php</title><link>http://wordpressapi.com/2010/06/02/how-to-use-memcached-with-php/</link> <comments>http://wordpressapi.com/2010/06/02/how-to-use-memcached-with-php/#comments</comments> <pubDate>Wed, 02 Jun 2010 13:43:46 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Memcached]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category> <category><![CDATA[cache]]></category> <category><![CDATA[linux]]></category> <category><![CDATA[Server]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2839</guid> <description><![CDATA[If you try to install memcached with Linux server then use following commands # yum install libevent # yum install libmemcached libmemcached-devel # yum install memcached For Starting the memcached server # memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody 11211 port is default port for memcached server. For using the memecached with.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/memcached-logo-200x152.png"><img
class="alignnone size-full wp-image-2840" title="memcached-logo-200x152" src="http://wordpressapi.com/files/memcached-logo-200x152.png" alt="" width="200" height="152" /></a></p><p>If you try to install memcached with Linux server then use following commands</p><p># yum install libevent<br
/> # yum install libmemcached libmemcached-devel<br
/> # yum install memcached</p><p>For Starting the memcached server<br
/> # memcached -d -m 512 -l 127.0.0.1 -p 11211 -u nobody</p><p>11211 port is default port for memcached server.</p><p>For using the memecached with php client you need to install following package</p><p># pecl install memcache</p><p>After installing all packages restart the apache server.</p><p># /etc/sbin/service httpd restart</p><pre class="brush: php;">
&lt;?php
/* OO API */
$memcache_obj = new Memcache;
$memcache_obj-&gt;connect('memcache_host', 11211);
$memcache_obj-&gt;set('any_key', 'some value', MEMCACHE_COMPRESSED, 50);
echo $memcache_obj-&gt;get('any_key');
?&gt;
</pre><p>Important Note: Memcached key has limitations of 250 charactors, So key value should be with in 250 charactors.</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/06/02/how-to-use-memcached-with-php/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>What is difference between die and exit in php</title><link>http://wordpressapi.com/2010/06/01/difference-die-exit-php/</link> <comments>http://wordpressapi.com/2010/06/01/difference-die-exit-php/#comments</comments> <pubDate>Tue, 01 Jun 2010 07:24:34 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2717</guid> <description><![CDATA[Many PHP developers are been asked this question in interview. But many times they are not sure about answer. There is no difference between die() and exit() function. They both are same and worked same. Again question is why php keep the both functions if they are same. Both functions are alias of each other.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/php-exit-die.jpg"><img
class="alignleft size-medium wp-image-2719" style="margin: 5px" title="php-exit-die" src="http://wordpressapi.com/files/php-exit-die-222x300.jpg" alt="" width="222" height="300" /></a>Many PHP developers are been asked this question in interview. But many times they are not sure about answer.</p><p>There is no difference between die() and exit() function. They both are same and worked same.<br
/> Again question is why php keep the both functions if they are same. Both functions are alias of each other function.</p><p>Due to API and keeping the backward compatibility both functions are kept.</p><p>Here is one more example:</p><p>is_int() and is_integer() are also same.</p><p>There are quite a few functions in PHP which you can call with more than one name. In some cases there is no preferred name among the multiple ones, is_int() and is_integer() are equally good for example. However there are functions which changed names because of an API cleanup or some other reason and the old names are only kept as aliases for backward compatibility. It is usually a bad idea to use these kind of aliases, as they may be bound to obsolescence or renaming, which will lead to unportable script. This list is provided to help those who want to upgrade their old scripts to newer syntax.</p><p>Full list of Aliases function you will find on following URL:</p><p>http://php.net/manual/en/aliases.php</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/06/01/difference-die-exit-php/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How to use sleep and usleep function in PHP</title><link>http://wordpressapi.com/2010/06/01/how-to-use-sleep-usleep-function-in-php/</link> <comments>http://wordpressapi.com/2010/06/01/how-to-use-sleep-usleep-function-in-php/#comments</comments> <pubDate>Tue, 01 Jun 2010 07:03:44 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2710</guid> <description><![CDATA[Sleep is very common method in every language. How sleep function works we need to understand. Sleep function delays the program execution for the given number of seconds. Usleep delays program execution for the given number of micro seconds. Following is the php example with sleep function &#60;?php echo date('h:i:s') . &#34;&#60;br /&#62;&#34;; //stop execution.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/php-sleep.jpg"><img
class="alignleft size-medium wp-image-2712" style="margin: 5px" title="php-sleep" src="http://wordpressapi.com/files/php-sleep-300x199.jpg" alt="" width="300" height="199" /></a>Sleep is very common method in every language. How sleep function works we need to understand.</p><p>Sleep function delays the program execution for the given number of seconds.<br
/> Usleep delays program execution for the given number of micro seconds.</p><p>Following is the php example with sleep function</p><pre class="brush: php;">
&lt;?php
echo date('h:i:s') . &quot;&lt;br /&gt;&quot;;

//stop execution for 30 seconds
sleep(30);

//start again
echo date('h:i:s');

?&gt;
</pre><p>Following is the php example with usleep function</p><pre class="brush: php;">
&lt;?php
echo date('h:i:s') . &quot;&lt;br /&gt;&quot;;

//stop execution for 30 seconds
usleep(30000000);

//start again
echo date('h:i:s');
?&gt;
</pre>]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/06/01/how-to-use-sleep-usleep-function-in-php/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>how to log the php error in log file with trigger_error</title><link>http://wordpressapi.com/2010/05/09/log-php-error-log-file-trigger_error/</link> <comments>http://wordpressapi.com/2010/05/09/log-php-error-log-file-trigger_error/#comments</comments> <pubDate>Sun, 09 May 2010 05:34:31 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category> <category><![CDATA[php error]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2113</guid> <description><![CDATA[In PHP language checking the logs and checking error is sometimes became difficult. PHP is offer inbuild solution to log all errors to a log fiie. First I will tell about creating the normal error log file. Open your pho.ini file and modify the following line. error_log = /var/log/php-error.log Make sure display_errors set to Off.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/PHP-trigger_error-Manual_1273383153544.png"><img
class="alignnone size-full wp-image-2114" title="PHP- trigger_error - Manual_1273383153544" src="http://wordpressapi.com/files/PHP-trigger_error-Manual_1273383153544.png" alt="" width="620" height="297" /></a>In PHP language checking the logs and checking error is sometimes became difficult.<br
/> PHP is offer inbuild solution to log all errors to a log fiie.</p><p>First I will tell about creating the normal error log file.<br
/> Open your pho.ini file and modify the following line.</p><p>error_log = /var/log/php-error.log</p><p>Make sure display_errors set to Off (no errors to end users)</p><p>display_errors = Off</p><p>This is normal way to check the php error log.</p><p>But if you want to check where is script is dying or you want to debug.<br
/> Then use trigger_error() function. Personaly I love to use this function for logging the php errors.</p><p>Using this function you can specify the custom error messages as per your script requirement.</p><pre class="brush: php;">
&lt;?php
$test = ture;
if ($test == true) {
trigger_error(&quot;A custom error has been triggered&quot;);
}
?&gt;
</pre><p>When you run this file and check the php error log file or you can check httpd/apache error log file.</p><p>you will got following error message.</p><p>Notice: A custom error has been triggered<br
/> in C:\webfolder\test.php on line 5</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/05/09/log-php-error-log-file-trigger_error/feed/</wfw:commentRss> <slash:comments>12</slash:comments> </item> <item><title>How to dectect ie7 or ie8 with php</title><link>http://wordpressapi.com/2010/05/08/dectect-ie7-ie8-php/</link> <comments>http://wordpressapi.com/2010/05/08/dectect-ie7-ie8-php/#comments</comments> <pubDate>Sat, 08 May 2010 07:08:14 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category> <category><![CDATA[ie]]></category> <category><![CDATA[IE7]]></category> <category><![CDATA[ie8]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2080</guid> <description><![CDATA[In daily development we face lot of cross browser issues and sometimes conditional css will never work as excepted. In this article I will show how to detect IE browser and IE 7 and IE8 using php language. Following function you can use for detecting the IE browsers. function detect_ie($navigator_user_agent) { if (stristr($navigator_user_agent, &#34;MSIE&#34;)) {.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/ie8-logo.png"><img
class="alignnone size-full wp-image-2081" title="ie8-logo" src="http://wordpressapi.com/files/ie8-logo.png" alt="" width="256" height="256" /></a>In daily development we face lot of cross browser issues and sometimes conditional css will never work as excepted.</p><p>In this article I will show how to detect IE browser and IE 7 and IE8 using php language.</p><p>Following function you can use for detecting the IE browsers.</p><pre class="brush: php;">

function detect_ie($navigator_user_agent)
{
 if (stristr($navigator_user_agent, &quot;MSIE&quot;))
 {
 return true;
 } else return false;
}

detect_ie($_SERVER['HTTP_USER_AGENT']);

//detect IE7 browser

function detect_ie7($navigator_user_agent)
{
 if (stristr($navigator_user_agent, &quot;msie 7&quot;))
 {
 return true;
 } else return false;
}

detect_ie7($_SERVER['HTTP_USER_AGENT']);

function detect_ie8($navigator_user_agent)
 {
 if (stristr($navigator_user_agent, &quot;msie 7&quot;))
 {
 return true;
 } else return false;
 }

detect_ie8($_SERVER['HTTP_USER_AGENT']);
</pre>]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/05/08/dectect-ie7-ie8-php/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>how to install php-pear on centos or redhat</title><link>http://wordpressapi.com/2010/05/01/install-php-pear-centos-redhat/</link> <comments>http://wordpressapi.com/2010/05/01/install-php-pear-centos-redhat/#comments</comments> <pubDate>Sat, 01 May 2010 06:23:32 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Open source]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[centos]]></category> <category><![CDATA[linux]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2051</guid> <description><![CDATA[For this example I used the RHEL 5.3 edition. If server is new then use follwoing commands to keep server up to date. When I tried to install php-pear lib in server I am not able to install all the pear libs. Then I Used following commands for installing the php-pear fully. # yum update.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/RedHat-CentOS-PHP-mysql.jpg"><img
class="alignnone size-full wp-image-2060" title="RedHat-CentOS-PHP-mysql" src="http://wordpressapi.com/files/RedHat-CentOS-PHP-mysql.jpg" alt="" width="300" height="225" /></a></p><p>For this example I used the RHEL 5.3 edition. If server is new then use follwoing commands to keep server up to date.<br
/> When I tried to install php-pear lib in server I am not able to install all the pear libs. Then I Used following commands for installing the php-pear fully.</p><p># yum update<br
/> # up2date -u<br
/> # yum install lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-eaccelerator php-magickwand php-magpierss php-mapserver php-mbstring php-mcrypt php-mhash php-mssql php-shout php-snmp php-soap php-tidy php-pear php-devel httpd-devel mysql-server mysql-devel</p><p>The 2 RPMs which we need are:<br
/> epel-release and remi-release</p><p># wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm<br
/> # rpm -Uvh epel-release-5-3.noarch.rpm</p><p># wget http://rpms.famillecollet.com/enterprise/remi-release-5.rpm<br
/> # rpm -Uvh remi-release-5.rpm</p><p># yum install php-pear*</p><p># /sbin/service httpd start<br
/> # /sbin/service mysqld start</p><p># php -v</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/05/01/install-php-pear-centos-redhat/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>How to check the duplicate values from array using php</title><link>http://wordpressapi.com/2010/05/01/check-duplicate-values-array-php/</link> <comments>http://wordpressapi.com/2010/05/01/check-duplicate-values-array-php/#comments</comments> <pubDate>Sat, 01 May 2010 06:12:27 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2046</guid> <description><![CDATA[Many times we need to array has duplicate values or not. Using php language this is very easy. For checking the duplicate array value array_unique function is very useful. Here I am giving you very simple php example: &#60;?php $array1 = array(&#34;banana&#34;,&#34;apple&#34;,&#34;pear&#34;,&#34;banana&#34;); if (count(array_unique($array1)) &#60; count($array1)) echo 'Duplicate entry found in array'; else echo 'No.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/php-array.jpg"><img
class="alignnone size-full wp-image-2047" title="php-array" src="http://wordpressapi.com/files/php-array.jpg" alt="" width="429" height="132" /></a>Many times we need to array has duplicate values or not. Using php language this is very easy.</p><p>For checking the duplicate array value array_unique function is very useful.</p><p>Here I am giving you very simple php example:</p><pre class="brush: php;">

&lt;?php
 $array1 = array(&quot;banana&quot;,&quot;apple&quot;,&quot;pear&quot;,&quot;banana&quot;);

 if (count(array_unique($array1)) &lt; count($array1))
 echo 'Duplicate entry found in array';
 else
 echo 'No Duplicate values found in array';
 ?&gt;
</pre><p>Output:  Duplicate entry found in array</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/05/01/check-duplicate-values-array-php/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>How to to check file exists or not using php</title><link>http://wordpressapi.com/2010/05/01/check-file-exists-php/</link> <comments>http://wordpressapi.com/2010/05/01/check-file-exists-php/#comments</comments> <pubDate>Sat, 01 May 2010 06:10:15 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2041</guid> <description><![CDATA[Many times we got requirement of check file from specific directory. Following code will work in all the system like (Mac, Linux and Windows). Using following php code you can check file is present or not in specific directory. &#60;?php $filename = '/var/www/html/test/test.txt'; if (file_exists($filename)) { echo &#34;The file $filename exists&#34;; } else { echo.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/php-file.jpg"><img
class="alignnone size-full wp-image-2042" title="php-file" src="http://wordpressapi.com/files/php-file.jpg" alt="" width="550" height="350" /></a>Many times we got requirement of check file from specific directory. Following code will work in all the system like (Mac, Linux and Windows).</p><p>Using following php code you can check file is present or not in specific directory.</p><pre class="brush: php;">

&lt;?php
 $filename = '/var/www/html/test/test.txt';

 if (file_exists($filename)) {
 echo &quot;The file $filename exists&quot;;
 } else {
 echo &quot;The file $filename does not exist&quot;;
 }

?&gt;
</pre>]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/05/01/check-file-exists-php/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>How to check string in string variable using php</title><link>http://wordpressapi.com/2010/05/01/check-string-string-variable-php/</link> <comments>http://wordpressapi.com/2010/05/01/check-string-string-variable-php/#comments</comments> <pubDate>Sat, 01 May 2010 06:03:54 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=2038</guid> <description><![CDATA[Use can use the strpos function for string to search in &#60;?php $mystring = 'abc xyz'; $findme   = 'abc'; $check_string = strpos($mystring, $findme); // because the position of 'a' was the 0th (first) character. if ($check_string === false) { echo &#34;The string '$findme' was not found in the string '$mystring'&#34;; } else { echo &#34;The.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/php-string.jpg"><img
class="alignnone size-full wp-image-2039" title="php-string" src="http://wordpressapi.com/files/php-string.jpg" alt="" width="400" height="300" /></a>Use can use the strpos function for string to search in</p><pre class="brush: php;">
&lt;?php
$mystring = 'abc xyz';
$findme   = 'abc';
$check_string = strpos($mystring, $findme);

// because the position of 'a' was the 0th (first) character.
if ($check_string === false) {
 echo &quot;The string '$findme' was not found in the string '$mystring'&quot;;
} else {
 echo &quot;The string '$findme' was found in the string '$mystring'&quot;;
 echo &quot; and exists at position $pos&quot;;
}
?&gt;
</pre>]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/05/01/check-string-string-variable-php/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>how to change date format in php</title><link>http://wordpressapi.com/2010/03/21/change-date-format-php/</link> <comments>http://wordpressapi.com/2010/03/21/change-date-format-php/#comments</comments> <pubDate>Sun, 21 Mar 2010 17:33:13 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=1879</guid> <description><![CDATA[If you want to change the date format and save into mysql database. You can use following php functions. Let say you are getting date in yyyy-mm-dd format and you want convert that into dd-mm-yyyy format and save into database. so you can use following function. $timestamp = strtotime(your date variable); $new_date = date('d-m-Y', $timestamp);.....]]></description> <content:encoded><![CDATA[<p>If you want to change the date format and save into mysql database. You can use following php functions.</p><p>Let say you are getting date in yyyy-mm-dd format and you want convert that into dd-mm-yyyy format and save into database. so you can use following function.</p><pre class="brush: php;">
$timestamp = strtotime(your date variable);
$new_date = date('d-m-Y', $timestamp);

// or use can following code

$new_date = date('d-m-Y', strtotime(your date variable));

// or use can following code

strftime ($time, '%d %m %Y')
</pre><p><a
href="http://wordpressapi.com/files/php-date-function.gif"><img
class="alignnone size-full wp-image-1880" title="php-date-function" src="http://wordpressapi.com/files/php-date-function.gif" alt="" width="400" height="400" /></a></pre> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/03/21/change-date-format-php/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>Solved : fopen and fread not working with url in php</title><link>http://wordpressapi.com/2010/03/04/solved-fopen-fread-working-url-php/</link> <comments>http://wordpressapi.com/2010/03/04/solved-fopen-fread-working-url-php/#comments</comments> <pubDate>Thu, 04 Mar 2010 09:20:17 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=1662</guid> <description><![CDATA[Many times we normally face problems while reading a file using url For e.g : $url = &#8216;http://somesite.com/somefile.txt&#8217;; $fp = fopen($url,&#8221;r&#8221;); To allow the fopen to get the contents of the file through url, do the following settings in php.ini file : allow_url_fopen = On allow_url_include = On By setting above 2 directives to &#8216;On&#8217;,.....]]></description> <content:encoded><![CDATA[<p>Many times we normally face problems while reading a file using url<br
/> For e.g :<br
/> $url = &#8216;http://somesite.com/somefile.txt&#8217;;<br
/> $fp = fopen($url,&#8221;r&#8221;);</p><p>To allow the fopen to get the contents of the file through url, do the following settings in php.ini file :<br
/> allow_url_fopen = On<br
/> allow_url_include = On</p><p>By setting above 2 directives to &#8216;On&#8217;, fopen will be able to read the contents from url.</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/03/04/solved-fopen-fread-working-url-php/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>How to execute linux commands using php</title><link>http://wordpressapi.com/2010/03/03/execute-linux-commands-php/</link> <comments>http://wordpressapi.com/2010/03/03/execute-linux-commands-php/#comments</comments> <pubDate>Wed, 03 Mar 2010 16:52:29 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[Linux]]></category> <category><![CDATA[Open source]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[linux]]></category> <category><![CDATA[linux commands]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=1658</guid> <description><![CDATA[Many times we need to run the linux commands using PHP language. This is my favorite question about PHP when I take interview of new PHP developer. In this article I will show you how to execute the linux command using PHP language syntax or script. You can execute linux commands within a php script.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/linux.jpg"><img
class="alignleft size-thumbnail wp-image-1659" title="linux" src="http://wordpressapi.com/files/linux-150x150.jpg" alt="" width="150" height="150" /></a>Many times we need to run the linux commands using PHP language. This is my favorite question about PHP when I take interview of new PHP developer.</p><p>In this article I will show you how to execute the linux command using PHP language syntax or script.</p><p>You can <strong>execute</strong> <strong>linux</strong> <strong>commands</strong> within a <strong>php</strong> script &#8211; all you have <strong>to</strong> do is put the command line in backticks (&#8221;) ,exec() , and shell_exec().</p><pre class="brush: php;">
$command = exec('linux command');
echo $command;
echo shell_exec('ll');
</pre>]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/03/03/execute-linux-commands-php/feed/</wfw:commentRss> <slash:comments>8</slash:comments> </item> <item><title>How to read xml using php</title><link>http://wordpressapi.com/2010/03/03/how-to-read-xml-using-php/</link> <comments>http://wordpressapi.com/2010/03/03/how-to-read-xml-using-php/#comments</comments> <pubDate>Wed, 03 Mar 2010 13:39:03 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[PHP]]></category> <category><![CDATA[XML]]></category> <category><![CDATA[tutorials]]></category> <category><![CDATA[xml]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=1653</guid> <description><![CDATA[Many new PHP developer looking for how to easily read the xml file. In this tutorial I will show you how to read the xml file using PHP language. This is my xml file format and file name is readxml.xml file &#60;?xml version=&#34;1.0&#34;?&#62; &#60;!-- our XML-document describes a purchase order --&#62; &#60;purchase-order&#62; &#60;date&#62;2005-10-31&#60;/date&#62; &#60;number&#62;12345&#60;/number&#62; &#60;purchased-by&#62;.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/xmlLogo.png"><img
class="alignleft size-medium wp-image-1654" title="xmlLogo" src="http://wordpressapi.com/files/xmlLogo-300x180.png" alt="" width="300" height="180" /></a>Many new PHP developer looking for how to easily read the xml file. In this tutorial I will show you how to read the xml file using PHP language.</p><p>This is my xml file format and file name is readxml.xml file</p><pre class="brush: xml;">

&lt;?xml version=&quot;1.0&quot;?&gt;

&lt;!-- our XML-document describes a purchase order --&gt;
&lt;purchase-order&gt;

 &lt;date&gt;2005-10-31&lt;/date&gt;
 &lt;number&gt;12345&lt;/number&gt;

 &lt;purchased-by&gt;
 &lt;name&gt;My name&lt;/name&gt;
 &lt;address&gt;My address&lt;/address&gt;
 &lt;/purchased-by&gt;

 &lt;!-- a collection element, contains a set of items --&gt;
 &lt;order-items&gt;

 &lt;item&gt;
 &lt;code&gt;687&lt;/code&gt;
 &lt;type&gt;CD&lt;/type&gt;
 &lt;label&gt;Some music&lt;/label&gt;
 &lt;/item&gt;

 &lt;item&gt;
 &lt;code&gt;129851&lt;/code&gt;
 &lt;type&gt;DVD&lt;/type&gt;
 &lt;label&gt;Some video&lt;/label&gt;
 &lt;/item&gt;

 &lt;/order-items&gt;

&lt;/purchase-order&gt;
</pre><p>This is one php file called test.php and code as follows</p><pre class="brush: php;">

&lt;?php
 //create new document object
 $dom_object = new DOMDocument();
 //load xml file
 $dom_object-&gt;load(&quot;test.xml&quot;);

 $item = $dom_object-&gt;getElementsByTagName(&quot;item&quot;);

 foreach( $item as $value )
 {
 $codes = $value-&gt;getElementsByTagName(&quot;code&quot;);
 $code  = $codes-&gt;item(0)-&gt;nodeValue;

 $types = $value-&gt;getElementsByTagName(&quot;type&quot;);
 $type  = $types-&gt;item(0)-&gt;nodeValue;

 $labels = $value-&gt;getElementsByTagName(&quot;label&quot;);
 $label  = $labels-&gt;item(0)-&gt;nodeValue;

 echo &quot;$code - $type - $label &lt;br&gt;&quot;;
 }
?&gt;
</pre><p>When you run the readxml.php file. you will see the following output.</p><p>687 &#8211; CD &#8211; Some music<br
/> 129851 &#8211; DVD &#8211; Some video</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/03/03/how-to-read-xml-using-php/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>How to work with PHP array</title><link>http://wordpressapi.com/2010/02/24/work-php-array/</link> <comments>http://wordpressapi.com/2010/02/24/work-php-array/#comments</comments> <pubDate>Wed, 24 Feb 2010 16:00:48 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[MySql]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category> <category><![CDATA[array]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=1492</guid> <description><![CDATA[If you are programmer then you dont need introduction of array. In every language array is the most important part. Using array we can achive so many things and array is useful for so many times when we do programming. In this article I am going to share some method about PHP array. What is.....]]></description> <content:encoded><![CDATA[<p>If you are programmer then you dont need introduction of array. In every language array is the most important part.</p><p>Using array we can achive so many things and array is useful for so many times when we do programming.<br
/> In this article I am going to share some method about PHP array.</p><p>What is PHP array?<br
/> An array in PHP is actually an ordered map. A map is a type that associates values to keys. This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more. As array values can be other arrays, trees and multidimensional arrays are also possible.</p><p>Following is syntax<br
/> array(key =&gt; value)</p><p>Creating PHP array:</p><pre class="brush: php;">
&lt;?php
$arr = array(&quot;str_arr&quot; =&gt; &quot;this is string&quot;, 25 =&gt; true);

echo $arr[&quot;str_arr&quot;]; // print this is string
echo $arr[25];    // print ture
?&gt;
</pre><p>How to print direct PHP array.</p><pre class="brush: php;">
&lt;?php
$arr=array(&quot;a&quot;=&gt;&quot;jimi&quot;,&quot;b&quot;=&gt;&quot;timi&quot;,&quot;c&quot;=&gt;&quot;limi&quot;);
print_r($arr);
?&gt;
</pre><p>How to print PHP array preformated</p><pre class="brush: php;">
&lt;?php
$arr=array(&quot;a&quot;=&gt;&quot;jimi&quot;,&quot;b&quot;=&gt;&quot;timi&quot;,&quot;c&quot;=&gt;&quot;limi&quot;);
print_r(&quot;&lt;pre&gt;&quot;.$arr);
?&gt;
</pre><p>How to create a two-dimensional PHP array</p><pre class="brush: php;">
&lt;?php
$arr = array (
 &quot;fruits&quot;  =&gt; array(&quot;a&quot; =&gt; &quot;orange&quot;, &quot;b&quot; =&gt; &quot;banana&quot;, &quot;c&quot; =&gt; &quot;apple&quot;),
 &quot;numbers&quot; =&gt; array(1, 2, 3, 4, 5, 6),
 &quot;holes&quot;   =&gt; array(&quot;first&quot;, 5 =&gt; &quot;second&quot;, &quot;third&quot;)
);
print_r(&quot;&lt;pre&gt;&quot;.$arr);
?&gt;
</pre><p>How to create an array from MySql table</p><pre class="brush: php;">
&lt;?
function cre_array($row) {
 foreach($row as $key =&gt; $value) {
 global $$key;
 $$key = $value;
 }
}

//User table has first_name field present.

$sql = mysql_query(&quot;SELECT * FROM 'users'&quot;);
while ($row = mysql_fetch_assoc($sql)) {
 cre_array($row);
 echo $first_name.'&lt;br&gt;'; //instead of $row['first_name']
}

?&gt;
</pre><p>How to count PHP array count</p><pre class="brush: php;">
$fruits = array(&quot;a&quot; =&gt; &quot;orange&quot;, &quot;b&quot; =&gt; &quot;banana&quot;, &quot;c&quot; =&gt; &quot;apple&quot;);
echo sizeof($fruits);
echo $arrayLength = count($fruits);
</pre><p>PHP and MySql and Array</p><pre class="brush: php;">
&lt;?php
$sql = &quot;SELECT key,value FROM table&quot;;
$result = mysql_query($sql);
while($row = mysql_fetch_row($result)) {
$myArray[$row[0]] = $row[1];
}

while(list($key,$value) = each($myArray)) {
echo &quot;$key : $value&quot;;
}
?&gt;
</pre><p>Following image will help you to understand two dimensional array.</p><p><a
href="http://wordpressapi.com/files/twodim-array.png"><img
class="alignnone size-medium wp-image-1493" title="twodim-array" src="http://wordpressapi.com/files/twodim-array-300x243.png" alt="" width="300" height="243" /></a></p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/02/24/work-php-array/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>how to use soap with php</title><link>http://wordpressapi.com/2010/02/23/soap-php/</link> <comments>http://wordpressapi.com/2010/02/23/soap-php/#comments</comments> <pubDate>Tue, 23 Feb 2010 19:43:42 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[JavaScript]]></category> <category><![CDATA[Open source]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[SOAP]]></category> <category><![CDATA[tutorials]]></category> <category><![CDATA[web service]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=1484</guid> <description><![CDATA[SOAP is a best technology that can help you in developing web services and amazing applications. Many times we heard about soap but we really dont know about what is soap. What is soap? SOAP, the Simple Object Access Protocol, is the powerhouse of web services. It’s a highly adaptable, object-oriented protocol that exists in.....]]></description> <content:encoded><![CDATA[<p>SOAP is a best technology that can help you in developing web services and amazing applications.</p><p>Many times we heard about soap but we really dont know about what is soap.</p><p>What is soap?</p><p><a
href="http://www.w3.org/TR/soap12-part0/">SOAP</a>, the Simple Object Access Protocol, is the powerhouse of web services. It’s a highly adaptable, object-oriented protocol that exists in over 80 implementations on every popular platform, including <a
href="http://developer.apple.com/documentation/AppleScript/Conceptual/AppleScriptLangGuide/index.html">AppleScript</a>, JavaScript, and Cocoa. It provides a flexible communication layer between applications, regardless of platform and location. As long as they both speak SOAP, a PHP-based web application can ask a C++ database application on another continent to look up the price of a book and have the answer right away. Another <a
href="http://developer.apple.com/internet/applescript/applescripttoperl.html">Internet Developer article</a> shows how to use SOAP with AppleScript and Perl.</p><p>If you want to use the soap then you need to install <strong>libxml </strong>on your server. In your PHP.ini file</p><p>you need to check following setting are available or not if not then put it.<strong> </strong></p><table><tbody><tr
valign="middle"><td
align="left">soap.wsdl_cache_enabled</td><td
align="left">1</td><td
align="left">PHP_INI_ALL</td><td
align="left"></td></tr><tr
valign="middle"><td
align="left">soap.wsdl_cache_dir</td><td
align="left">/tmp</td><td
align="left">PHP_INI_ALL</td><td
align="left"></td></tr><tr
valign="middle"><td
align="left">soap.wsdl_cache_ttl</td><td
align="left">86400</td><td
align="left">PHP_INI_ALL</td><td
align="left"></td></tr><tr
valign="middle"><td
align="left">soap.wsdl_cache</td><td
align="left">1</td><td
align="left">PHP_INI_ALL</td><td
align="left"></td></tr><tr
valign="middle"><td
align="left">soap.wsdl_cache_limit</td><td
align="left">5</td><td
align="left">PHP_INI_ALL</td></tr></tbody></table><p>SOAP is an XML-based web service protocol. The most common external specifications used by a SOAP-based service is WSDL to describe its available services, and that, in turn, usually relies on XML Schema Data (XSD) to describe its data types. In order to &#8220;know&#8221; SOAP, it would be extremely useful to have some knowledge of WSDL and XSD. This will allow one to figure out how to use the majority of SOAP services.</p><p>Here is the basic WSDL Structure</p><pre class="brush: xml;">

&lt;definitions&gt;
 &lt;types&gt;
 …
 &lt;/types&gt;
 &lt;message&gt;
 …
 &lt;/message&gt;
 &lt;portType&gt;
 …
 &lt;/portType&gt;
 &lt;binding&gt;
 …
 &lt;/binding&gt;
 &lt;/definitions&gt;
</pre><p>Filled example:</p><pre class="brush: xml;">
 &lt;xsd:complexType name=&quot;ResultElement&quot;&gt;
 &lt;xsd:all&gt;
 &lt;xsd:element name=&quot;summary&quot; type=&quot;xsd:string&quot;/&gt;
 &lt;xsd:element name=&quot;URL&quot; type=&quot;xsd:string&quot;/&gt;
 &lt;xsd:element name=&quot;snippet&quot; type=&quot;xsd:string&quot;/&gt;
 &lt;xsd:element name=&quot;title&quot; type=&quot;xsd:string&quot;/&gt;
 &lt;xsd:element name=&quot;cachedSize&quot; type=&quot;xsd:string&quot;/&gt;
 &lt;xsd:element name=
 &quot;relatedInformationPresent&quot; type=&quot;xsd:boolean&quot;/&gt;
 &lt;xsd:element name=&quot;hostName&quot; type=&quot;xsd:string&quot;/&gt;
 &lt;xsd:element name=
 &quot;directoryCategory&quot; type=&quot;typens:DirectoryCategory&quot;/&gt;
 &lt;xsd:element name=&quot;directoryTitle&quot; type=&quot;xsd:string&quot;/&gt;
 &lt;/xsd:all&gt;
 &lt;/xsd:complexType&gt;
</pre><p>Soap is nothing but xml format web service to talk with cross domain servers. There are othere ways also to create web services. XML-RPC is good one and that is not to much hard to learn also. Use can use following code in your PHP file.</p><pre class="brush: php;">

// create a soap object
 $Soap_Object = new SoapClient(&quot;http://anywebsite.com/any.wsdl&quot;, array('trace' =&gt; true));

 // setting params to authenticate to web service
 $params_Authenticate = array('username' =&gt; 'username', 'password' =&gt; 'password');

 // authenticate to web service
 $do_login=  $Soap_Object-&gt;login($params_Authenticate);

 // take sesstion id from anywebsite.com
 $your_session_id= $do_login-&gt;loginReturn-&gt;sessionId;

 // Set the query parameters.

 $soap_query = 'select book_id from Time where book = 52435455';
 paramsQry = array('queryString' =&gt; $soap_query);

 // Make a soap call.
 $objResponse = $Soap_Object-&gt;query(paramsQry);

 header('Content-Type: text/xml; ');
 print($Soap_Object-&gt;__getLastRequest());
</pre><p>Soap is nothing but a web service with xml so use PHP functions to create the Soap service. Following graph will help you to understand more and in detail about SOAP.</p><p><a
href="http://wordpressapi.com/files/soap-webservice.gif"><img
class="alignleft size-medium wp-image-1485" title="soap-webservice" src="http://wordpressapi.com/files/soap-webservice-300x153.gif" alt="" width="300" height="153" /></a></p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/02/23/soap-php/feed/</wfw:commentRss> <slash:comments>11</slash:comments> </item> <item><title>How to send emails using PHP language</title><link>http://wordpressapi.com/2010/02/23/how-to-send-emails-using-php-language/</link> <comments>http://wordpressapi.com/2010/02/23/how-to-send-emails-using-php-language/#comments</comments> <pubDate>Tue, 23 Feb 2010 17:18:35 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[Open source]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[tutorials]]></category> <category><![CDATA[email]]></category> <category><![CDATA[php code]]></category> <category><![CDATA[php script]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=1477</guid> <description><![CDATA[Many PHP programmers facing this issue and hitting same wall which is already hitted. PHP itself provides the mail() function to send emails. In this article I will show you the options of sending email using PHP language. If you are using linux or windows hosting service for running the PHP application. PHP mail() function.....]]></description> <content:encoded><![CDATA[<p><a
href="http://wordpressapi.com/files/PHPmailer.jpg"><img
class="alignleft size-thumbnail wp-image-1480" title="PHPmailer" src="http://wordpressapi.com/files/PHPmailer-150x150.jpg" alt="" width="150" height="150" /></a>Many PHP programmers facing this issue and hitting same wall which is already hitted.</p><p>PHP itself provides the mail() function to send emails. In this article I will show you the options of sending email using PHP language.</p><p>If you are using linux or windows hosting service for running the PHP application. PHP mail() function uses the sendmail mail server to send emails.<br
/> If sendmail mail server is configured and running on linux server then only mail() function is able to send the emails.</p><p>First we will talk about mail() function. You can pass the following parameters to mail function.</p><pre class="brush: php;">
mail(to,subject,message,headers,parameters)
</pre><p>Sample code as follows:</p><pre class="brush: php;">
&lt;?php
$to = &quot;support@wordpressapi.com, wordpressapi@gmail.com&quot;;
$subject = &quot;Test mail&quot;;
$message = &quot;This is a simple email message. &lt;br&gt; this is seond line.&quot;;
$from = &quot;some@example.com, wordpressapi@gmail.com&quot;;

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . &quot;\r\n&quot;;
$headers .= 'Content-type: text/html; charset=iso-8859-1' . &quot;\r\n&quot;;
$headers .= &quot;From: $from&quot;;

$headers .= 'Cc: test@test1.com' . &quot;\r\n&quot;;
$headers .= 'Bcc: test2@test1.com' . &quot;\r\n&quot;;

mail($to,$subject,$message,$headers);
echo &quot;Mail Sent.&quot;;
?&gt;
</pre><p>If sendmail mail server is not configured on your server, mostly with windows server then there is issue.<br
/> But you can send email using anothere PHP programm called PHPmailer.<br
/> you can download the PHPmailer from following URL:</p><p>http://sourceforge.net/projects/phpmailer/</p><p>Download first PHPmailer and extract the phpmailer folder and in that folder you will find the following three files.<br
/> 1. class.phpmailer.php<br
/> 2. class.pop3.php<br
/> 3. class.smtp.php</p><p>copy and paste the following files to your PHP application. and use the following code in case of use POP email</p><pre class="brush: php;">
&lt;?php
function sendmail_wordpressapi($to,$from,$subject,$body,$id){
//error_reporting(E_ALL);
error_reporting(E_STRICT);
date_default_timezone_set('America/Toronto');
include_once('class.phpmailer.php');
//include(&quot;class.smtp.php&quot;); // optional, gets called from within class.phpmailer.php if not already loaded
$mail             = new PHPMailer();
$mail-&gt;IsSMTP(); // telling the class to use SMTP
$mail-&gt;Host       = &quot;wordpressapi.com&quot;; // SMTP server
$mail-&gt;From       = $from;
$mail-&gt;FromName   = $from;
$mail-&gt;Subject    = $subject;
$mail-&gt;Body       = $body;
$mail-&gt;AltBody    = &quot;To view the message, please use an HTML compatible email viewer!&quot;; // optional, comment out and test
$mail-&gt;WordWrap   = 50; // set word wrap
$mail-&gt;MsgHTML($body);
$mail-&gt;AddAddress($to, $to);

if(!$mail-&gt;Send()) {
$mail             = new PHPMailer();
$mail-&gt;IsSMTP();
$mail-&gt;SMTPAuth   = true;                  // enable SMTP authentication
$mail-&gt;SMTPSecure = &quot;ssl&quot;;                 // sets the prefix to the servier
$mail-&gt;Host       = &quot;smtp.gmail.com&quot;;      // sets GMAIL as the SMTP server
$mail-&gt;Port       = 465;                   // set the SMTP port for the GMAIL server
$mail-&gt;Username   = &quot;WORDPRESSAPI@gmail.com&quot;;  // GMAIL username
$mail-&gt;Password   = &quot;YOURPASSWORD&quot;;            // GMAIL password
$mail-&gt;AddReplyTo(&quot;smtp.production@gmail.com&quot;,&quot;wordpressapi&quot;);
$mail-&gt;From       = &quot;support@wordpressapi.com&quot;;
$mail-&gt;FromName   = &quot;SMTP EMAIL-wordpressapi&quot;;
$mail-&gt;Subject    = &quot;email server is having some issue&quot;;
$mail-&gt;Body       = &quot;Hi,&lt;br&gt;email server is having some issue,&lt;br&gt; check this out&quot;;                      //HTML Body
$mail-&gt;AltBody    = &quot;To view the message, please use an HTML compatible email viewer!&quot;; // optional, comment out and test
$mail-&gt;WordWrap   = 50; // set word wrap
$mail-&gt;MsgHTML($body);
$mail-&gt;AddAddress(&quot;support@wordpressapi.com&quot;, &quot;support-wordpressapi&quot;);
$mail-&gt;IsHTML(true); // send as HTML
$mail-&gt;Send();

} else {
 echo &quot;Message sent!&quot;;
}
}
?&gt;
</pre><p>I created above function in this function I am using SMTP mail function for sending email but in case mail is not going using SMTP details.<br
/> you can also send emails using your gmail account details. you can edit or use this function as your requirement.</p><p>You can pass following parameters to sendmail_wordpressapi function:</p><p>sendmail_wordpressapi($to,$from,$subject,$body,$id);</p><p>You can send email to multiple email addresses. I am sure using above code sending emails through PHP is very easy. If you have any quries..write to me.</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/02/23/how-to-send-emails-using-php-language/feed/</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>get alexa ranking using php code</title><link>http://wordpressapi.com/2010/02/19/alexa-ranking-php-code/</link> <comments>http://wordpressapi.com/2010/02/19/alexa-ranking-php-code/#comments</comments> <pubDate>Fri, 19 Feb 2010 19:57:30 +0000</pubDate> <dc:creator>Sony</dc:creator> <category><![CDATA[Open source]]></category> <category><![CDATA[PHP]]></category> <category><![CDATA[google]]></category> <category><![CDATA[news]]></category> <category><![CDATA[seo]]></category> <category><![CDATA[technology]]></category> <category><![CDATA[tutorials]]></category> <category><![CDATA[web design]]></category> <category><![CDATA[alexa]]></category> <category><![CDATA[php code]]></category> <category><![CDATA[php script]]></category> <category><![CDATA[SEO]]></category> <category><![CDATA[website ranking]]></category><guid
isPermaLink="false">http://wordpressapi.com/?p=1246</guid> <description><![CDATA[if you want to check the your website ranking as per alexa so you can use the following code in your php projects. http://data.alexa.com/data?cli=10&#38;dat=s&#38;url=wordpressapi &#8220;http://data.alexa.com/data&#8221; this file will return the xml format output. Using the XML output or reading xml file we can easily fetch the our or any website ranking. Use the following function.....]]></description> <content:encoded><![CDATA[<p>if you want to check the your website ranking as per alexa so you can use the following code in your php projects.</p><p>http://data.alexa.com/data?cli=10&amp;dat=s&amp;url=wordpressapi</p><p>&#8220;http://data.alexa.com/data&#8221; this file will return the xml format output. Using the XML output or reading xml file we can easily fetch the our or any website ranking.</p><p>Use the following function for getting the alexa website ranking.</p><pre class="brush: php;">
&lt;?php
function AlexaRank( $url )
{
preg_match( '#&lt;POPULARITY URL=&quot;(.*?)&quot; TEXT=&quot;([0-9]+){1,}&quot;/&gt;#si', file_get_contents('http://data.alexa.com/data?cli=10&amp;dat=s&amp;url=' . $url), $p );
return ( $p[2] ) ? number_format( intval($p[2]) ):0;
}

echo &quot;wordpressapi.com Rank as per alexa.com: &quot;;
echo AlexaRank('wordpressapi.com');

?&gt;</pre><p>if you want to check the multiple website ranking in one shot than use the following PHP code.</p><pre class="brush: php;">
&lt;?php
$domains = array( 'google.com', 'ask.com', 'yahoo.com', 'bing.com' );

foreach ( $domains as $domain )
echo $domain, ' - ', AlexaRank( $domain ), '&lt;br /&gt;', PHP_EOL;

?&gt;</pre><p><a
href="http://wordpressapi.com/files/alexa-icon-photoshop-tutorial.jpg"><img
class="alignnone size-medium wp-image-1255" title="alexa-icon-photoshop-tutorial" src="http://wordpressapi.com/files/alexa-icon-photoshop-tutorial-300x225.jpg" alt="" width="300" height="225" /></a></p><p>Have fun!</p> ]]></content:encoded> <wfw:commentRss>http://wordpressapi.com/2010/02/19/alexa-ranking-php-code/feed/</wfw:commentRss> <slash:comments>27</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (user agent is rejected)
Database Caching 150/223 queries in 1.221 seconds using disk

Served from: wordpressapi.com @ 2010-09-09 20:48:08 -->