<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-6780330443694982799</atom:id><lastBuildDate>Wed, 28 Aug 2024 20:03:09 +0000</lastBuildDate><category>php</category><category>blog  intro</category><category>calender</category><category>command line</category><category>date</category><category>dead</category><category>equation</category><category>general post</category><category>month</category><category>week</category><title>Daily Coding  Blog</title><description>THIS BLOG IS DEDICATED TO MY DAILY CODING JOB. HERE I WRITE ABOUT MY EVERYDAY HACKS AND THE PROBLEMS THAT I FACE OCCASIONALLY WHILE CODING...</description><link>http://i-code-today.blogspot.com/</link><managingEditor>noreply@blogger.com (Unknown)</managingEditor><generator>Blogger</generator><openSearch:totalResults>12</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-1706390402748435772</guid><pubDate>Mon, 15 Feb 2010 06:17:00 +0000</pubDate><atom:updated>2010-02-14T22:31:23.870-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">dead</category><title>this blog is dead</title><description>The title pretty much says it all. After months of writing &quot;i-code-today&quot; a.k.a &quot;daily coding blog&quot;, I am closing down shop and shifting to a hosted wordpress blog. My new blog address is &lt;a href=&quot;http://blog.raysourav.com/&quot;&gt;http://blog.raysourav.com&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2010/02/this-blog-is-dead.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-3281560636049829955</guid><pubDate>Tue, 05 Jan 2010 06:09:00 +0000</pubDate><atom:updated>2010-01-05T01:18:31.829-08:00</atom:updated><title>The PHP Array Project : Lost and Found</title><description>Last year January I read an article at http://debuggable.com with  title &quot;Donate your PHP arrays!&quot;.  In that article &lt;a href=&quot;http://debuggable.com/about&quot;&gt;Felix Geisendörfer&lt;/a&gt; has asked all opensource enthusiasts to donate some useful lists of data in php array format. No doubt it&#39;s a noble idea, but after almost one year  I found it&#39;s too difficult to find the project on google search page. Anyway I found it finally because luckily I remember the blog name. No!! I don&#39;t want to lost the links again.&lt;br /&gt;&lt;br /&gt;Here are the useful links:&lt;br /&gt;&lt;a href=&quot;http://debuggable.com/posts/donate-your-php-arrays:49811879-9c6c-4985-8850-76c54834cda3&quot;&gt;   The original blog post&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://github.com/debuggable/php_arrays/tree/master&quot;&gt;   The project&lt;/a&gt;&lt;br /&gt;&lt;a href=&quot;http://github.com/debuggable/php_arrays/zipball/master&quot;&gt;   Download project&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2010/01/php-array-project-lost-and-found.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-2756742745918569465</guid><pubDate>Tue, 15 Sep 2009 05:17:00 +0000</pubDate><atom:updated>2009-09-15T11:30:31.813-07:00</atom:updated><title>Opera 10 rocks the Acid Test 3</title><description>Yesterday night I have downloaded the latest version of opera. The browser has great look (I mean the new cool UI), lots of goodies and is as reliable as its preceding versions. I was  more inquisit   to see how it will perform in Acid Test 3. &lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfrTOTFTUXRvZI6pk_rVbM3FOTexPxDpidcgsyMooGiMk-nphm54WAYxB7seMGHXfSrMNppLHV4CJioJBBhDZ-h4_xDPIdnYe6AnEL7a2gMSrWgTxUVQ3DCVMK7GgxSsiKMG8y5PUd-c8/s1600-h/opera-acid-test-3.jpg&quot;&gt;&lt;img style=&quot;margin: 0px auto 10px; display: block; text-align: center; cursor: pointer; width: 320px; height: 294px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfrTOTFTUXRvZI6pk_rVbM3FOTexPxDpidcgsyMooGiMk-nphm54WAYxB7seMGHXfSrMNppLHV4CJioJBBhDZ-h4_xDPIdnYe6AnEL7a2gMSrWgTxUVQ3DCVMK7GgxSsiKMG8y5PUd-c8/s320/opera-acid-test-3.jpg&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5381563227470455522&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;FireFox 3.5 does really well with an impressive 93/100 score and I expect Opera 10 to perform similarly, but it stunned me with a &lt;span style=&quot;font-weight: bold;&quot;&gt;100/100&lt;/span&gt; score.&lt;br /&gt;O dear! that&#39;s why I Love Opera.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/09/opera-10-rocks-acid-test-3.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgfrTOTFTUXRvZI6pk_rVbM3FOTexPxDpidcgsyMooGiMk-nphm54WAYxB7seMGHXfSrMNppLHV4CJioJBBhDZ-h4_xDPIdnYe6AnEL7a2gMSrWgTxUVQ3DCVMK7GgxSsiKMG8y5PUd-c8/s72-c/opera-acid-test-3.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-1093591135868268762</guid><pubDate>Thu, 28 May 2009 17:35:00 +0000</pubDate><atom:updated>2009-05-31T22:19:49.114-07:00</atom:updated><title>FTP but no SCP.  WTF!</title><description>Today my hosting provider (Yes I am going to start a new blog at &lt;a href=&quot;http://raysourav.com&quot;&gt;http://raysourav.com&lt;/a&gt;) told me that he can provide me FTP access but not any SCP access when I have access to the jailed shell.&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;font-style: italic; font-weight: bold; color: rgb(102, 102, 102);&quot;&gt;Dear hosting service provider , this is really ridiculous .I guess you don&#39;t understand what security means&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;&lt;span style=&quot;color: rgb(102, 102, 102);&quot;&gt;!&lt;/span&gt;&quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/05/ftp-but-no-scp-wtf.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-1604941569181477491</guid><pubDate>Thu, 12 Mar 2009 02:29:00 +0000</pubDate><atom:updated>2009-03-11T19:39:29.620-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">calender</category><category domain="http://www.blogger.com/atom/ns#">date</category><category domain="http://www.blogger.com/atom/ns#">equation</category><category domain="http://www.blogger.com/atom/ns#">month</category><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">week</category><title>Calculating Week of the Month from a given date [ PHP ]</title><description>Let first understand the problem. In the following fig. we have 2 months calendar of March 2009 to April 2009.&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk3DBcGsgLrEaGb8Jt7h7rTsYsHSpRL-1XWYZl7ISKGU8r-hXM4aMPdK1frl8nJUXo1iQdQA_NFsxTR24DMJvbr0Kfa__GyBady7yT2wMpcyX46LCeLGN3cKMqH2H7TxZtXsXYRGbq_EU/s1600-h/week_of_the_month.JPG&quot;&gt;&lt;img style=&quot;cursor: pointer; width: 248px; height: 272px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk3DBcGsgLrEaGb8Jt7h7rTsYsHSpRL-1XWYZl7ISKGU8r-hXM4aMPdK1frl8nJUXo1iQdQA_NFsxTR24DMJvbr0Kfa__GyBady7yT2wMpcyX46LCeLGN3cKMqH2H7TxZtXsXYRGbq_EU/s320/week_of_the_month.JPG&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5312124226972041170&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;        &lt;p class=&quot;MsoNormal&quot;&gt;Now 31&lt;sup&gt;st&lt;/sup&gt; March and 1&lt;sup&gt;st&lt;/sup&gt; April, both dates belong to 14&lt;sup&gt;th&lt;/sup&gt; Week of the Year, but in Week of the Month Calculation 31&lt;sup&gt;st&lt;/sup&gt; March will be 5&lt;sup&gt;th&lt;/sup&gt; Week of March and 1&lt;sup&gt;st&lt;/sup&gt; April will be 1&lt;sup&gt;st&lt;/sup&gt; Week of April. &lt;span style=&quot;&quot;&gt; &lt;/span&gt;There is no such format is available for PHP date() function&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;, so we will calculate the Week of the Month Programmatically.&lt;o:p&gt;&lt;/o:p&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;Test Case: the program should return 1&lt;sup&gt;st&lt;/sup&gt; week of March and 2&lt;sup&gt;nd&lt;/sup&gt; Week of April respectively for given dates (dd/mm/yyyy) 07/03/2009&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;and 07/04/2009.&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;The Week of the Month can be determined by following equation&lt;br /&gt;&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5vAkQckBu_fykrtaJBb43T9wl_hrOMh7HxMTaYzlxlcVifjX5EBC3R4aWV-xV3AXM0zfG1nBNoXPlnEhx-HFxm5sib-vw1RPavHR8DraxMTGYit4rLr8B3K5mC32z0vahnMDqtZUvmjU/s1600-h/week_of_the_month_equ.JPG&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 320px; height: 291px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5vAkQckBu_fykrtaJBb43T9wl_hrOMh7HxMTaYzlxlcVifjX5EBC3R4aWV-xV3AXM0zfG1nBNoXPlnEhx-HFxm5sib-vw1RPavHR8DraxMTGYit4rLr8B3K5mC32z0vahnMDqtZUvmjU/s320/week_of_the_month_equ.JPG&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5312123890461750418&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;  &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;We can implement the equation in a PHP function as bellow&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/p&gt;                    &lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: rgb(51, 51, 153);&quot;&gt; function getWeekOfTheMonth($dateTimestamp)&lt;br /&gt; {&lt;br /&gt;&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;$d = date(&#39;j&#39;,$ dateTimestamp);&lt;br /&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;$w = date(&#39;w&#39;,$ dateTimestamp)+1;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;//add 1 because date returns value between 0 to 6&lt;br /&gt;&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;$dt= &lt;span style=&quot;&quot;&gt; &lt;/span&gt;(floor($dayOfMonth % 7)!=0)? floor($dayOfMonth % 7) : 7;&lt;br /&gt;&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;$k = (($w-$dt) &lt; style=&quot;&quot;&gt;      &lt;/span&gt;$W= ceil(($dayOfMonth+$k)/7);&lt;br /&gt;&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;return $W ;&lt;br /&gt; }&lt;/span&gt;&lt;br /&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;                      &lt;p class=&quot;MsoNormal&quot;&gt;Now check the function with Test Cases.&lt;br /&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;For 07/03/2009 or 7&lt;sup&gt;th&lt;/sup&gt; March 2009:&lt;br /&gt;&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;&lt;span style=&quot;color: rgb(51, 51, 153);&quot;&gt;$dateTimestamp = mktime(0,0,0,3,7,2009);&lt;br /&gt;&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;echo&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;getWeekOfTheMonth($dateTimestamp) .&quot; week of &quot;.date(F,$dateTimestamp);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;&quot;&gt;     &lt;/span&gt;and the o/p is&lt;br /&gt;&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;&lt;b style=&quot;&quot;&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:green;&quot;&gt;1 week of March&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;For 07/04/2009 or 7&lt;sup&gt;th&lt;/sup&gt; April 2009&lt;br /&gt;&lt;span style=&quot;color: rgb(51, 51, 153);&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;$dateTimestamp = mktime(0,0,0,4,7,2009);&lt;br /&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;echo&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;getWeekOfTheMonth($dateTimestamp) .&quot; week of &quot;.date(F,$dateTimestamp);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;&quot;&gt;     &lt;/span&gt;and the o/p is&lt;br /&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;b style=&quot;&quot;&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:green;&quot;&gt;2 week of April&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;/p&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/03/calculating-week-of-month-from-given.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgk3DBcGsgLrEaGb8Jt7h7rTsYsHSpRL-1XWYZl7ISKGU8r-hXM4aMPdK1frl8nJUXo1iQdQA_NFsxTR24DMJvbr0Kfa__GyBady7yT2wMpcyX46LCeLGN3cKMqH2H7TxZtXsXYRGbq_EU/s72-c/week_of_the_month.JPG" height="72" width="72"/><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-3863768640167861969</guid><pubDate>Fri, 20 Feb 2009 11:50:00 +0000</pubDate><atom:updated>2009-02-20T04:50:17.525-08:00</atom:updated><title>Singleton Class, Object Cloning and Object Foreach</title><description>&lt;h3&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;After the lunch we (Anand, Avlesh, Jaimin, Ashish, Aakash and yours truly) have a light hearted discussion about object and classes. We were wandering if we can clone a singleton class object? Obviously we all differ with others opinion and finally draw the same conclusion that logically you can clone a singleton class object. This is something disappointing for programmer like &lt;span style=&quot;&quot;&gt; &lt;/span&gt;me who loves to write singleton class to implement single access point, but thankfully in php generally we are not &lt;span style=&quot;&quot;&gt; &lt;/span&gt;sharing anything between two processes so the threat is really less.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;Returning &lt;span style=&quot;&quot;&gt; &lt;/span&gt;to my desk I wrote a small script to verify my understanding. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;&quot;&gt;          &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;class SimpleClass&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;margin-left: 0.5in; text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;public $var3 = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;margin-left: 0.5in; text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;public function __toString(){&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;margin-left: 0.5in; text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;     &lt;/span&gt;return strval($this-&gt;var3);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;margin-left: 0.5in; text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;class TestSingletonCloning&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;     &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;static $classInstance;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;public $var1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;public $var2 = &#39;value 2&#39;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;private function TestSingletonCloning()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;{&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;$this-&gt;var1= new SimpleClass();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;margin-left: 1in; text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;$this-&gt;var2 = &#39;value 2&#39;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;     &lt;/span&gt;&lt;span style=&quot;&quot;&gt;     &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;public static function init()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;if(!isset(TestSingletonCloning::$classInstance) ||&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;empty(TestSingletonCloning::$classInstance) )&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;                     &lt;/span&gt;TestSingletonCloning::$classInstance = new TestSingletonCloning();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;$inst = &amp;amp; TestSingletonCloning::$classInstance;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;return $inst;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;     &lt;/span&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;$obj1 &lt;span style=&quot;&quot;&gt; &lt;/span&gt;= &lt;span style=&quot;&quot;&gt; &lt;/span&gt;TestSingletonCloning::init();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;$obj2 &lt;span style=&quot;&quot;&gt; &lt;/span&gt;= &lt;span style=&quot;&quot;&gt; &lt;/span&gt;TestSingletonCloning::init();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;$obj3 &lt;span style=&quot;&quot;&gt; &lt;/span&gt;= &lt;span style=&quot;&quot;&gt; &lt;/span&gt;clone $obj1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;$obj3-&gt;var1-&gt;var3 ++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;$obj3-&gt;var2 &lt;span style=&quot;&quot;&gt; &lt;/span&gt;= &#39;value 3&#39;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;var_dump($obj1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;var_dump($obj2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3 style=&quot;&quot;&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;var_dump($obj3);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;After executing the piece of code &lt;span style=&quot;&quot;&gt; &lt;/span&gt;I got result like following&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;pre&gt;object(TestSingletonCloning)#1 (2) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[&quot;var1&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;object(SimpleClass)#2 (1) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;[&quot;var3&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;int(2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[&quot;var2&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;string(7) &quot;value 2&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;object(TestSingletonCloning)#1 (2) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[&quot;var1&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;object(SimpleClass)#2 (1) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;[&quot;var3&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;int(2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[&quot;var2&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;string(7) &quot;value 2&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;object(TestSingletonCloning)#3 (2) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[&quot;var1&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;object(SimpleClass)#2 (1) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;[&quot;var3&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;int(2)&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[&quot;var2&quot;]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;string(7) &quot;value 3&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;}&lt;/pre&gt;  &lt;h3&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;It is a desired result that I got.&lt;/span&gt; Hurrah!!!&lt;span style=&quot;font-weight: normal;&quot;&gt; We have successfully cloned the object of the singleton class. As object Cloning bypasses the constructor call by replicating the object map ( or what ever &lt;span style=&quot;&quot;&gt; &lt;/span&gt;lies beneath your object)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;In PHP the cloning is a shallow copying by default like most of OO languages. So the cloned object points to the same object referred by $val1.Any modification in $var1 of clone Object will affect the object referred by $var1 of the original Object. If desire to change this behavior implement deep copying logic in the magic method&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;__clone of the singleton class. &lt;span style=&quot;&quot;&gt; &lt;/span&gt;That definitely not solves the problem of having multiple object versions of a singleton class. If you like to stop developer to clone your singleton class, you can throw an exception within __clone function .&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Now going by the definition of PHP &lt;/span&gt;&lt;i style=&quot;&quot;&gt;foreach&lt;/i&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt; the last solution, suppose to fail you if you try to iterate over the singleton object using a foreach outside of the class. But it will not, because your object which is supposed to be cloned before iteration, is &lt;span style=&quot;&quot;&gt; &lt;/span&gt;actual shallow copied via an implementation other than Cloning. So the copying process never calls the __clone method of you singleton class . Try this out before dumping all…&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;foreach($obj1 as $key =&gt; $value) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;if($key==&#39;var1&#39;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;                &lt;/span&gt;$obj1-&gt;var1-&gt;var3 ++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;&lt;span style=&quot;&quot;&gt;           &lt;/span&gt;echo &quot;$key =&gt; $value&lt;br /&gt;&quot;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;;font-family:&amp;quot;;font-size:11;&quot;  &gt;}&lt;/span&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;  &lt;h3&gt;&lt;span style=&quot;font-weight: normal;&quot;&gt;Finally some relief for my soul. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/02/singleton-class-object-cloning-and_3552.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-4681604515506069473</guid><pubDate>Tue, 17 Feb 2009 14:21:00 +0000</pubDate><atom:updated>2009-02-17T07:10:40.036-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">general post</category><title>Favicon for I-Code Today</title><description>&lt;a onblur=&quot;try {parent.deselectBloggerImageGracefully();} catch(e) {}&quot; href=&quot;http://i-code-today.blogspot.com/&quot;&gt;&lt;img style=&quot;margin: 0pt 10px 10px 0pt; float: left; cursor: pointer; width: 68px; height: 68px;&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9dpK-hUIxIhMj8rRuYUMxJPYHHi5cDVuTpQIVNsmOaTCmkY9PGH8sWPeqnassqqSrR7zFyWAjBFb2v5nYfxyMA9cQR3znhtB4tY191j1Z-AxkxBgooPnAf1IiyEIHlT-ni3dMIQXFeOI/s320/favicon.png&quot; alt=&quot;&quot; id=&quot;BLOGGER_PHOTO_ID_5303771538411042594&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&lt;br /&gt;As this blog is gaining popularity (average 240 unique users per day form 11th Feb ), I thought now it should have an unique Favicon .&lt;br /&gt;I tried to keep the color pallet inline with the blog color.&lt;br /&gt;&lt;br /&gt;Dear Readers... do I have to say .. &quot;I am looking for your feedback!&quot;.   Thank you guys.. for visiting this blog :)&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;color: rgb(204, 0, 0);&quot;&gt;(c) Sourav Ray&lt;/span&gt;    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/02/favicon-for-i-code-today.html</link><author>noreply@blogger.com (Unknown)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9dpK-hUIxIhMj8rRuYUMxJPYHHi5cDVuTpQIVNsmOaTCmkY9PGH8sWPeqnassqqSrR7zFyWAjBFb2v5nYfxyMA9cQR3znhtB4tY191j1Z-AxkxBgooPnAf1IiyEIHlT-ni3dMIQXFeOI/s72-c/favicon.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-7538017572997900882</guid><pubDate>Thu, 12 Feb 2009 05:24:00 +0000</pubDate><atom:updated>2009-02-12T03:35:35.247-08:00</atom:updated><title>PHP array, foreach loop with references and no block-scope  –  a killer recipe</title><description>&lt;p class=&quot;MsoNormal&quot;&gt;Today morning I was browsing through my collection ridiculous php bugs ( I have 20+ such code snippet now) and my eyes got stuck to this problem. I cannot remember from where I got this one but surely it’s a jewel in my collection.&lt;/p&gt;      &lt;p class=&quot;MsoNormal&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;Let give a look to the original code&lt;br /&gt;&amp;lt;?php&lt;/p&gt;  &lt;pre&gt;&lt;span style=&quot;color:blue;&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;$arr&lt;/span&gt; = &lt;span style=&quot;color: rgb(0, 0, 102);&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;&#39;A&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;B&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;C&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;D&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;E&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt; &lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;as&lt;/span&gt; &amp;amp;&lt;span style=&quot;color:blue;&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;{}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt; &lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color:blue;&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;{}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 102);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;?&amp;gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;The problem is that the var_dump gives a result &lt;/p&gt;  &lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;array(5) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[0]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&amp;amp;string(1) &quot;A&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[1]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&amp;amp;string(1) &quot;B&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[2]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&amp;amp;string(1) &quot;C&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[3]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&amp;amp;string(1) &quot;D&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;[4]=&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&amp;amp;string(1) &quot;D&quot;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/i&gt;Shocked! Aaha… who screwed up your array? Apparently it’s your references&lt;br /&gt;and variable scopes. You get it right but you will be biased if you don’t&lt;br /&gt;criticize the lack of block-scope in php. &lt;/pre&gt;&lt;pre&gt;In the first foreach block we are assigning reference of the each element&lt;br /&gt;to $val. Thus at the end of the first foreach loop $val actually a reference&lt;br /&gt;to the final index of array $arr.&lt;/pre&gt;&lt;pre&gt;Now as there is no concept of block-scope in php, the $val will retain the&lt;br /&gt;reference to the final index $arr at the start of the second loop (&lt;i style=&quot;&quot;&gt;pathetic&lt;/i&gt;!).&lt;/pre&gt;&lt;pre&gt;&lt;o:p&gt; &lt;/o:p&gt;We can simply represent the situation as bellow&lt;/pre&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&amp;lt;?php&lt;/p&gt;  &lt;pre&gt;&lt;span style=&quot;color:blue;&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;$arr&lt;/span&gt; = &lt;span style=&quot;color: rgb(0, 0, 102);&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;&#39;A&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;B&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;C&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;D&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;E&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$val = &lt;/span&gt;&amp;amp;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt;&lt;span style=&quot;color:purple;&quot;&gt;[4]&lt;/span&gt; ;&lt;span style=&quot;color:blue;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt; &lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color:blue;&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;{}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 102);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;    &lt;p class=&quot;MsoNormal&quot;&gt;?&amp;gt;&lt;br /&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;pre&gt;Now doing a &lt;span style=&quot;font-weight: bold;&quot;&gt;var_dump of $arr inside the second foreach&lt;/span&gt; loop gives us the&lt;br /&gt;following result.&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;array (&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;0 =&gt; &#39;A&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;1 =&gt; &#39;B&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;2 =&gt; &#39;C&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;3 =&gt; &#39;D&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;4 =&gt; &#39;A&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;)&lt;br /&gt;&lt;br /&gt;array (&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;0 =&gt; &#39;A&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;1 =&gt; &#39;B&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;2 =&gt; &#39;C&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;3 =&gt; &#39;D&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;4 =&gt; &#39;B&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;)&lt;br /&gt;&lt;br /&gt;array (&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;0 =&gt; &#39;A&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;1 =&gt; &#39;B&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;2 =&gt; &#39;C&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;3 =&gt; &#39;D&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;4 =&gt; &#39;C&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;)&lt;br /&gt;&lt;br /&gt;array (&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;0 =&gt; &#39;A&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;1 =&gt; &#39;B&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;2 =&gt; &#39;C&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;3 =&gt; &#39;D&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;4 =&gt; &#39;D&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;)&lt;br /&gt;&lt;br /&gt;array (&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;0 =&gt; &#39;A&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;1 =&gt; &#39;B&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;2 =&gt; &#39;C&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;3 =&gt; &#39;D&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;4 =&gt; &#39;D&#39;,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/i&gt;&lt;/pre&gt;&lt;pre&gt;&lt;i style=&quot;&quot;&gt;&lt;span style=&quot;color:teal;&quot;&gt;)&lt;/span&gt;&lt;/i&gt; &lt;/pre&gt;&lt;pre&gt;So it is clear now the second foreach loop actually assigns value of&lt;br /&gt;each index one by one to the index referred by $val (final index).&lt;/pre&gt;&lt;pre&gt;&lt;o:p&gt; &lt;/o:p&gt;Now try out this solution &lt;/pre&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&amp;lt;?php&lt;/p&gt;  &lt;pre&gt;&lt;span style=&quot;color:blue;&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;$arr&lt;/span&gt; = &lt;span style=&quot;color: rgb(0, 0, 102);&quot;&gt;array&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;&#39;A&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;B&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;C&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;D&#39;&lt;/span&gt;, &lt;span style=&quot;color:red;&quot;&gt;&#39;E&#39;&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt; &lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;as&lt;/span&gt; &amp;amp;&lt;span style=&quot;color:blue;&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;{}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;color: rgb(51, 102, 255);&quot;&gt;unset&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt;;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;foreach&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt; &lt;span style=&quot;color: rgb(177, 177, 0);&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color:blue;&quot;&gt;$val&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;{}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style=&quot;color: rgb(0, 0, 102);&quot;&gt;&lt;span style=&quot;&quot;&gt;   &lt;/span&gt;var_dump&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;$arr&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 204, 102);&quot;&gt;)&lt;/span&gt;;&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;?&amp;gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/p&gt;  &lt;pre&gt;&lt;b style=&quot;&quot;&gt;IT WORKS &lt;/b&gt;&lt;b style=&quot;&quot;&gt;&lt;span style=&quot;font-family:Wingdings;&quot;&gt;&lt;span style=&quot;&quot;&gt;:)&lt;/span&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/pre&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/02/php-array-foreach-loop-with-references.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-583168643223073791</guid><pubDate>Fri, 30 Jan 2009 09:23:00 +0000</pubDate><atom:updated>2009-01-30T03:14:34.732-08:00</atom:updated><title>Sending mail Attachment(s) with PHP mail function (PART - II) : The Code</title><description>In my&lt;a href=&quot;http://i-code-today.blogspot.com/2009/01/sending-mail-attachments-with-php-mail.html&quot;&gt; previous post&lt;/a&gt; we saw the thumb rules for emailing using php mail function. Now we will implement those rules in code.   &lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;I have written a function &lt;b style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;sendMail&lt;/span&gt;&lt;/b&gt;, which &lt;span style=&quot;color:black;&quot;&gt;receives mail subject, message, senders &lt;span style=&quot;&quot;&gt; &lt;/span&gt;email id and destination id. I also accept three optional parameters, namely cc, bcc and attachment file list. &lt;span style=&quot;&quot;&gt; &lt;/span&gt;The function prepares appropriate mail headers and call &lt;i style=&quot;&quot;&gt;mail&lt;/i&gt; function to send mail via SMTP server. The function returns &lt;i style=&quot;&quot;&gt;true&lt;/i&gt; for mailing success and otherwise it will return &lt;i style=&quot;&quot;&gt;false&lt;/i&gt;.&lt;/span&gt;&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;text-indent: 0.5in;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;br /&gt;function&lt;/span&gt;&lt;span style=&quot;&quot;&gt; &lt;span style=&quot;color:black;&quot;&gt;sendMail(&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$subject&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$from&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$to&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$cc&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;=null,&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$bcc&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;=null,&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$attachment&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;=null)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;{&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$headers&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&#39;From: &#39;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$from&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;(!is_null(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$cc&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;)){&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$headers&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&#39;Cc: &#39;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$cc&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;(!is_null(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$bcc&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;)){&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$headers&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&#39;Bcc: &#39;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$bcc&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$headers&lt;/span&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&#39;MIME-Version: 1.0&#39;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                                                           &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;(is_array(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$attachment&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;count(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$attachment&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;)&gt;&lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;){&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$headers&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;mailAttachmentHeader (&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$attachment&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt; &lt;span style=&quot;color:blue;&quot;&gt;else&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;{&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$headers&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&#39;Content-type: text/html; charset=iso-8859-1&#39;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;(is_array(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$attachment&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;)&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;count(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$attachment&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;)&gt;&lt;/span&gt;&lt;span style=&quot;color:red;&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;){&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$message&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&#39;&#39;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$mailStatus&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;mail(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$to&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$subject&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$headers&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;echo&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\nNew Mailer\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$mailStatus&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;){&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color:blue;&quot;&gt;true&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;else&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;{&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color:blue;&quot;&gt;false&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;color:black;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;In mail function&lt;span style=&quot;&quot;&gt; &lt;/span&gt;&quot;Form &quot;, &quot;Cc &quot; , &quot;Bcc&quot;, &quot;&#39;MIME-Version&quot;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;set without checking if attachment is present or not – &lt;b style=&quot;&quot;&gt;Rule 1&lt;/b&gt;.&lt;/p&gt;      &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;Next we check is if attachments are present.&lt;br /&gt;&lt;span style=&quot;&quot;&gt;    &lt;/span&gt;In case of no attachment we set &lt;span style=&quot;&quot;&gt;&#39;Content-type: text/html; charset=iso-8859-1&#39;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;&quot;&gt;&quot;\r\n&quot; &lt;/span&gt;– &lt;b style=&quot;&quot;&gt;Rule 2.a&lt;/b&gt;. &lt;span style=&quot;&quot;&gt; &lt;/span&gt;Otherwise we call the &lt;b style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;mailAttachmentHeader&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;function to prepare the attachment header &lt;/p&gt;        &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;The massage is set to blank&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;– &lt;b style=&quot;&quot;&gt;Rule 3.b&lt;/b&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;color:blue;&quot;&gt;function&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;mailAttachmentHeader(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$attachment&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;,&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$message&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;{&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$mime_boundary&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;md5(time());&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;Content-Type: multipart/mixed; boundary=\&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$mime_boundary&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\&quot;\r\n\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;--&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$mime_boundary&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;Content-Type: text/plain; charset=\&quot;iso-8859-1\&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;Content-Transfer-Encoding: 7bit\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$message&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;         &lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;foreach&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$attachment&lt;/span&gt; &lt;span style=&quot;color:blue;&quot;&gt;as&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;{&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;--&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$mime_boundary&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;Content-Type: application/octet-stream; name=\&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.basename(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;Content-Transfer-Encoding: base64\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;Content-Disposition: attachment; filename=\&quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.basename(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$content&lt;/span&gt;&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;=&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;file_get_contents(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;chunk_split(base64_encode(&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$content&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;));&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;                  &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;--&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$mime_boundary&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;--\r\n\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;            &lt;/span&gt;&lt;span style=&quot;color:blue;&quot;&gt;return&lt;/span&gt; &lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$xMessage&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;      &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;br /&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;color:black;&quot;&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;o:p&gt;  &lt;/o:p&gt;Parameters passed to &lt;b style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;mailAttachmentHeader &lt;/span&gt;&lt;/b&gt;function are list of attachments and the functions returns headers &lt;i style=&quot;&quot;&gt;string&lt;/i&gt;. &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;In &lt;b style=&quot;&quot;&gt;&lt;span style=&quot;&quot;&gt;mailAttachmentHeader &lt;/span&gt;&lt;/b&gt;function we set &lt;span style=&quot;&quot;&gt;&quot;Content-Type: multipart/mixed; bundary=\&quot;&quot;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;&quot;&gt;$mime_boundary&lt;/span&gt;&lt;span style=&quot;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;&quot;&gt;&quot;\&quot;\r\n\r\n&quot;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;; where value of &lt;/span&gt;&lt;span style=&quot;&quot;&gt;$mime_boundary is the MD5 of current timestamp. &lt;/span&gt;– &lt;b style=&quot;&quot;&gt;Rule 2.b&lt;/b&gt;.&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;To denote starting of message and each attachment following code is added&lt;br /&gt;&lt;span style=&quot;&quot;&gt;$xMessage&lt;/span&gt;&lt;span style=&quot;&quot;&gt; &lt;span style=&quot;color:black;&quot;&gt;.=&lt;/span&gt; &lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;--&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;$mime_boundary&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: rgb(0, 130, 0);&quot;&gt;&quot;\r\n\r\n&quot;&lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;; &lt;/span&gt;&lt;/span&gt;– &lt;b style=&quot;&quot;&gt;Rule 3.b&lt;/b&gt;.&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;We add Content-type&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;“text/html” for message and “application/octet-stream” for attachments – &lt;b style=&quot;&quot;&gt;Rule 4&lt;/b&gt;&lt;span style=&quot;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;For each attachment we add &lt;span style=&quot;&quot;&gt;&quot;Content-Transfer-Encoding: base64\r\n&quot;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;; &lt;/span&gt;– &lt;b style=&quot;&quot;&gt;Rule 5&lt;/b&gt;&lt;span style=&quot;&quot;&gt; and &lt;/span&gt;&lt;span style=&quot;&quot;&gt;&quot;Content-Disposition: attachment; filename=\&quot;&quot;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;.basename(&lt;/span&gt;&lt;span style=&quot;&quot;&gt;$file&lt;/span&gt;&lt;span style=&quot;&quot;&gt;).&lt;/span&gt;&lt;span style=&quot;&quot;&gt;&quot;\&quot;\r\n&quot;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;; &lt;/span&gt;– &lt;b style=&quot;&quot;&gt;Rule 6&lt;/b&gt;&lt;span style=&quot;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;At the end of the function we add &lt;span style=&quot;&quot;&gt;&quot;--&quot;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;&quot;&gt;$mime_boundary&lt;/span&gt;&lt;span style=&quot;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;&quot;&gt;&quot;--\r\n\r\n&quot;&lt;/span&gt;&lt;span style=&quot;&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:black;&quot;&gt;to denote the end of attachment mail header&lt;/span&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;– &lt;b style=&quot;&quot;&gt;Rule 7&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot;&gt;&lt;b style=&quot;&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/b&gt;Now you can use the send mail function to send mail with or without any attachment. Cheers!! &lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot;&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  (c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/01/n-my-previous-post-we-saw-thumb-rules.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>5</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-4794509317974331066</guid><pubDate>Wed, 28 Jan 2009 08:41:00 +0000</pubDate><atom:updated>2009-01-28T20:28:39.432-08:00</atom:updated><title>Sending mail Attachment(s) with PHP mail function (PART -I) : Rules Of Thumb</title><description>&lt;p class=&quot;MsoNormal&quot;&gt;A few days ago I was writing a script that would send email with (or without) any number of attachments. I started googling for help and ended up with some code snippets that didn’t work. After spending few more frustrating hours debugging those scripts, I finally reached the solution (“Tank you! Anand, Kunal and Avlesh… for your suggestions”). &lt;span style=&quot;&quot;&gt; &lt;/span&gt;The problem with those scripts was that they were missing some crucial pieces of mail header and it was really a daunting task to fix those bugs, because “trial &#39;n error” was the only option left. That’s why in this post I tried to formulate a set of rules to send mail using mail() function with or without any attachment. &lt;/p&gt;    &lt;p style=&quot;font-weight: bold;&quot; class=&quot;MsoNormal&quot;&gt;The Rules:&lt;/p&gt;  &lt;ol style=&quot;margin-top: 0in;&quot; start=&quot;1&quot; type=&quot;1&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;In the      mail header few header elements (like &quot;Form &quot;, &quot;Cc &quot; ,      &quot;Bcc&quot;, &quot;&#39;MIME-Version&quot; )&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;will remain as it is, irrespective      of&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;the fact that the mail has any      attachment or not.&lt;/li&gt;&lt;/ol&gt;    &lt;ol style=&quot;margin-top: 0in;&quot; start=&quot;2&quot; type=&quot;1&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;  a.&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;If&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;a mail doesn&#39;t contain any attachment,      then &lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;Content-type &lt;/span&gt;will be &quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;text/html&lt;/span&gt;&quot;      (for html formatted mail) or &quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;text/plain&lt;/span&gt;&quot; ( for plain text mail)      . Content-type should have an additional attribute &quot;charset&quot; to define      character encoding of the message.&lt;/li&gt;&lt;/ol&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in;&quot;&gt;b. &lt;span style=&quot;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;In case when mail consists of one or more attachments, &lt;span style=&quot;font-weight: bold;&quot;&gt;Content-type&lt;/span&gt; will be &quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;multipart/mixed&lt;/span&gt;&quot;. Content-type will also have an attribute called &quot;boundary&quot;.&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;The &quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;boundary&lt;/span&gt;&quot;&lt;span style=&quot;font-weight: bold;&quot;&gt; &lt;/span&gt;attribute contains a &lt;span style=&quot;font-style: italic;&quot;&gt;unique signature &lt;/span&gt;which is use to denote the starting point of each message/attachment of the mail as well as the end of mail.&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;  &lt;ol style=&quot;margin-top: 0in;&quot; start=&quot;3&quot; type=&quot;1&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;  a.&lt;span style=&quot;&quot;&gt;  &lt;/span&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;In      case of mail without attachment the &lt;span style=&quot;font-weight: bold;&quot;&gt;message string&lt;/span&gt; should be passed to      mail   function as &lt;span style=&quot;font-style: italic;&quot;&gt;message parameter&lt;/span&gt;.&lt;/li&gt;&lt;/ol&gt;    &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in;&quot;&gt;b. &lt;span style=&quot;&quot;&gt;  &lt;/span&gt;If mail contains one or more attachments, then the &lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;message &lt;/span&gt;and the &lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;attachment file&lt;/span&gt; contents will be attached to the header string, separated by a boundary notation &lt;/p&gt;&lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in;&quot;&gt;&lt;span style=&quot;&quot;&gt;        &lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;-- &lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;[boundary value]&lt;/span&gt;&lt;/p&gt;  &lt;p class=&quot;MsoNormal&quot; style=&quot;margin-left: 0.5in;&quot;&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;&lt;span style=&quot;&quot;&gt; &lt;/span&gt;the start message will also have similar boundary notation to denote the start of message and A blank string or null value should be passed to the message parameter of mail function.&lt;/p&gt;    &lt;ol style=&quot;margin-top: 0in;&quot; start=&quot;4&quot; type=&quot;1&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;In      multipart mail each &lt;span style=&quot;font-style: italic;&quot;&gt;message/attachment will have their own Content-type&lt;/span&gt; . For      a multipart mail header the message will have Content-type      &quot;text/html&quot; (for html formatted mail) or &quot;text/plain&quot;      (for plain text mail). And attachment will have Content-type depending      upon the type of content. If you are not sure about content use      &lt;span style=&quot;font-weight: bold;&quot;&gt;Content-type&lt;/span&gt; &quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;application/octet-stream&lt;/span&gt;&quot;. For attachment content      type Additional Attribute name can be use to denote the base name of the      attachment file. &lt;/li&gt;&lt;/ol&gt;    &lt;ol style=&quot;margin-top: 0in;&quot; start=&quot;5&quot; type=&quot;1&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;Each      attachment block also contain header &quot;&lt;span style=&quot;font-weight: bold;&quot;&gt;Content-Transfer-Encoding&lt;/span&gt;&quot;      to specify the &lt;span style=&quot;font-style: italic;&quot;&gt;content encoding&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;    &lt;ol style=&quot;margin-top: 0in;&quot; start=&quot;6&quot; type=&quot;1&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;Each      attachment block will have&lt;span style=&quot;font-weight: bold;&quot;&gt; Content-Disposition&lt;/span&gt; as &quot;&lt;span style=&quot;font-style: italic;&quot;&gt;attachment&lt;/span&gt;&quot;      and attribute &lt;span style=&quot;font-weight: bold;&quot;&gt;filename &lt;/span&gt;will denote the&lt;span style=&quot;font-style: italic;&quot;&gt; name of the downloaded file&lt;/span&gt;.&lt;/li&gt;&lt;/ol&gt;    &lt;ol style=&quot;margin-top: 0in;&quot; start=&quot;7&quot; type=&quot;1&quot;&gt;&lt;li class=&quot;MsoNormal&quot; style=&quot;&quot;&gt;After      the end of all attachments there will be end of mail notation &lt;/li&gt;&lt;/ol&gt; &lt;p class=&quot;MsoNormal&quot;&gt;           &lt;span style=&quot;font-weight: bold;&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;[boundary value]&lt;/span&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;--&lt;/span&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;/p&gt;&lt;br /&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-size:85%;&quot;&gt;Note : &lt;span style=&quot;font-style: italic;&quot;&gt;To be on the safe side it is better to encode the attachment content to some standard encoding and set the Content-Transfer-Encoding as per the implemented encoding&lt;/span&gt;.&lt;/span&gt;&lt;/p&gt;    &lt;p class=&quot;MsoNormal&quot;&gt;In the next Post we will see how to implement these Rules in actual code&lt;/p&gt;&lt;o:p&gt;&lt;/o:p&gt; (c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/01/sending-mail-attachments-with-php-mail.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-8774944579160435872</guid><pubDate>Fri, 23 Jan 2009 03:03:00 +0000</pubDate><atom:updated>2009-01-22T22:46:40.175-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">command line</category><category domain="http://www.blogger.com/atom/ns#">php</category><title>PHP! Taking arguments from Command Line</title><description>Setting up Command Line Interface SAPI for php&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;In *nix environment:&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;Since PHP 4.3.0 the both --enable-cli and --enable-cgi are enabled by default. If a module SAPI is chosen during configure, such as apxs, or the --disable-cgi option is used, the CLI is copied to {PREFIX}/bin/php during make install otherwise the CGI is placed there. If you want to override the installation of the CGI binary, use make install-cli after make install. Alternatively you can specify --disable-cgi in your configure line.&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-weight: bold; font-style: italic;&quot;&gt;In windows:&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;PHP 5, the CLI is distributed in the main folder, named php.exe. The CGI version is distributed as php-cgi.exe.  &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now consider this CLI hello world programme&lt;br /&gt;File: cli-hello-world.co&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;code&gt;&lt;span style=&quot;font-size:10;&quot;&gt;fwrite&lt;/span&gt;(STDOUT,&lt;span style=&quot;color: rgb(0, 153, 0);&quot;&gt;&quot;&lt;/span&gt;&lt;/code&gt;&lt;span style=&quot;color: rgb(0, 153, 0);&quot;&gt;CLI hello world&lt;/span&gt;&lt;code&gt;&lt;span style=&quot;font-size:10;&quot;&gt;&lt;span style=&quot;color: rgb(0, 153, 0);&quot;&gt; \n&quot;&lt;/span&gt;);&lt;/span&gt;&lt;/code&gt;&lt;span style=&quot;&quot;&gt;&lt;br /&gt;&lt;/span&gt;?&gt;&lt;br /&gt;&lt;p class=&quot;MsoNormal&quot;&gt;To call this script from command line (we assume that php bin path is set in OS environment variable )&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;  &lt;span style=&quot;font-weight: bold;&quot;&gt;&gt;_ php cli-hello-world.com&lt;/span&gt;&lt;/p&gt;&lt;p class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;font-style: italic; color: rgb(102, 102, 102);&quot;&gt;CLI hello world&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;br /&gt;To passing an argument to php script from command line is similar to C or Java.  There are two global variables $argc and $argv, that hold an integer value of number of arguments passed and an array of sting value of the arguments respectively.&lt;br /&gt;Note:  if no additional parameter is passed  then the arg variables only will contain the file name and the value of $argc will be 1&lt;br /&gt;&lt;br /&gt;For example&lt;br /&gt;File : cli-arg.php&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;   &lt;/span&gt;&lt;span style=&quot;&quot;&gt;&lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;if&lt;/span&gt;($argc &gt; 1) &lt;/span&gt;&lt;br /&gt;{&lt;br /&gt; &lt;span style=&quot;color: rgb(0, 0, 153);&quot;&gt;foreach&lt;/span&gt; ($argv as $argumentVariable)&lt;br /&gt;    &lt;span style=&quot;color: rgb(255, 0, 0);&quot;&gt;fwrite&lt;/span&gt;(STDOUT, $argumentVariable. &lt;span style=&quot;color: rgb(0, 153, 0);&quot;&gt;&quot;/n&quot;&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;span style=&quot;color: rgb(102, 0, 0);&quot;&gt;?&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Now we can call this script like&lt;br /&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;  &gt;_ php cli-arg.php &quot;Hello World&quot;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic;&quot;&gt;        &lt;span style=&quot;color: rgb(102, 102, 102);&quot;&gt;cli-arg.php&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-style: italic; color: rgb(102, 102, 102);&quot;&gt;        Hello World&lt;/span&gt;&lt;br /&gt;&lt;p&gt;In PHP 5, the CLI version will always populate the global &lt;var class=&quot;varname&quot;&gt;$argv&lt;/var&gt; and &lt;var class=&quot;varname&quot;&gt;$argc&lt;/var&gt; variables  regardless of any &lt;tt class=&quot;filename&quot;&gt;php.ini&lt;/tt&gt; directive setting. Even having  &lt;span style=&quot;font-weight: bold;&quot;&gt;register_argc_argv &lt;span style=&quot;font-style: italic;&quot;&gt;set to&lt;/span&gt;  &lt;/span&gt;&lt;var style=&quot;font-weight: bold;&quot; class=&quot;literal&quot;&gt;off&lt;/var&gt;&lt;span style=&quot;font-weight: bold;&quot;&gt;  &lt;/span&gt;will have &lt;span style=&quot;font-weight: bold;&quot;&gt;no affect in CLI&lt;/span&gt;. &lt;/p&gt;&lt;br /&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/01/setting-up-command-line-interface-sapi.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6780330443694982799.post-2025927739108779635</guid><pubDate>Thu, 22 Jan 2009 12:53:00 +0000</pubDate><atom:updated>2009-01-22T22:44:07.678-08:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">blog  intro</category><title>&quot; हेल्लो World &quot;</title><description>Finally I have stared a blog that will keep an account to all my coding tricks. This was a long pending task since my previous blog was closed. My official blog is yet to be online, it is coming soon...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;(c) Sourav Ray    &lt;a rel=&quot;license&quot; href=&quot;http://creativecommons.org/licenses/by-sa/2.5/in/&quot;&gt;&lt;img alt=&quot;Creative Commons License&quot; style=&quot;border-width: 0pt;&quot; src=&quot;http://i.creativecommons.org/l/by-sa/2.5/in/80x15.png&quot; /&gt;&lt;/a&gt;&lt;div class=&quot;blogger-post-footer&quot;&gt;This blog is a personal Code Snippet Repository of Sourav Ray [raysourav@aol.in]&lt;/div&gt;</description><link>http://i-code-today.blogspot.com/2009/01/world.html</link><author>noreply@blogger.com (Unknown)</author><thr:total>0</thr:total></item></channel></rss>