<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Beginnercode.com &#187; php</title>
	<atom:link href="http://www.beginnercode.com/category/computing/programming/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.beginnercode.com</link>
	<description>The adventures of an amateur coder</description>
	<lastBuildDate>Thu, 15 Apr 2010 20:17:16 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
  <link>http://www.beginnercode.com</link>
  <url>http://www.beginnercode.com/wp-content/themes/neuron/favicon.ico</url>
  <title>Beginnercode.com</title>
</image>
		<item>
		<title>php: Checking if a directory is empty</title>
		<link>http://www.beginnercode.com/2008/02/21/php-checking-if-a-directory-is-empty/</link>
		<comments>http://www.beginnercode.com/2008/02/21/php-checking-if-a-directory-is-empty/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 15:16:19 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/index.php/2008/02/21/php-checking-if-a-directory-is-empty/</guid>
		<description><![CDATA[I found myself working with text files a little more recently and was looking for a way to tell if a directory was empty. Why? In my case I wanted to check if a directory was empty. If it wasn&#8217;t, to grab the data in those files and put them in a database.
What I didn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I found myself working with text files a little more recently and was looking for a way to tell if a directory was empty. Why? In my case I wanted to check if a directory was empty. If it wasn&#8217;t, to grab the data in those files and put them in a database.</p>
<p>What I didn&#8217;t want to do was have the expense of connecting to a database if the directory didn&#8217;t have any files in it to begin with. After chatting with my good friend TDavid at <a href="http://www.php-scripts.com/">php-scripts.com</a>, I decide to run with his suggestion&#8230;</p>
<p>Fill (or don&#8217;t fill) a variable with information if there were files in the directory. Then test the var to confirm or deny if there are files in the directory. It&#8217;s really a small bit of code&#8230;</p>
<pre class="brush: php;">
//----- Check if ticket dir has files. If it has files,
// set a variable to hold the list of file names.

$dir = &quot;../path/to/my/textfiles&quot;;      // set directory

if($handle = opendir($dir)){           // open directory

	while(($file = readdir($handle)) !== false){
		if($file != &quot;.&quot; &amp;&amp; $file != &quot;..&quot;){
			$file_list[] = $file;  // Set file list variable
		}

	}

	closedir($handle);      // Close directory
}
</pre>
<p>If there are files in this directory, the variable $file_list would not only exist, but also contain files. For example&#8230;</p>
<pre class="brush: php;">
Array
(
    [0] =&gt; 195972.txt
    [1] =&gt; 196027.txt
    [2] =&gt; 196053.txt
    [3] =&gt; 196067.txt...
)
</pre>
<p>If there aren&#8217;t any files in this directory, the variable $file_list would not even exist because no $file would be inserted into it. At this point we can check/ test the variable to output or do further processing&#8230;</p>
<pre class="brush: php;">
if(isset($file_list)){
    echo &quot;This dir has files!&quot;;
    // perform further processing
    // eg: collect each files contents
} else {
    echo &quot;This dir has NO files!&quot;;
    // stop processing
    // Not much do do with this since there are no files
}
</pre>
<p>Of course there are a few ways of checking to see if a directory is empty, but this way seemed to be the most simplistic to me. If you wanted to you could turn the entire lot into a function for reuse, and less script code clutter.</p>
<p>Comments? Questions?</p>
<p><tags>php, empty directory</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2008/02/21/php-checking-if-a-directory-is-empty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL Conditional Insert</title>
		<link>http://www.beginnercode.com/2007/12/20/mysql-conditional-insert/</link>
		<comments>http://www.beginnercode.com/2007/12/20/mysql-conditional-insert/#comments</comments>
		<pubDate>Thu, 20 Dec 2007 22:13:05 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php Snippets]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/index.php/2007/12/20/mysql-conditional-insert/</guid>
		<description><![CDATA[I came across a situation where I needed to pull records from 1 db to another on a recurring basis. I read many different ways to do it via searching around the net. Some of the suggestions included creating a temporary table and copying it over. What was lacking was that sometimes the new table [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a situation where I needed to pull records from 1 db to another on a recurring basis. I read many different ways to do it via searching around the net. Some of the suggestions included creating a temporary table and copying it over. What was lacking was that sometimes the new table also needed to be UPDATED, as the information changed from the original table.</p>
<p>I&#8217;ve come up with a dirty little example to show this can be done. There are <i>more</i> keywords that can enhance the <b><a href="http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html">ON DUPLICATE KEY UPDATE</a></b> function even more. The Example is assuming an &#8220;employees&#8221; table that looks like so:</p>
<table style="border-collapse:collapse;border:1px solid #000;">
<tr>
<th>employees</th>
</tr>
<tr>
<td style ="border:1px solid #000;">id (PK)</td>
</tr>
<tr>
<td style="border:1px solid #000;">first_name</td>
</tr>
</table>
<p>For brevity, I&#8217;ve left out connection data etc;</p>
<pre class="brush: php;">
$myArray = array(0 =&gt; array('id' =&gt; '1', 'fname' =&gt; 'Steve'),
                      array('id' =&gt; '2', 'fname' =&gt; 'sara'),
                      array('id' =&gt; '3', 'fname' =&gt; 'Matt')
                 );

// Don't forget to validate &amp; clean your data
// Connect to db here 

foreach($myArray as $key =&gt; $value){
          $query = &quot;INSERT INTO employees
          (id, first_name) VALUES ('$value[id]', '$value[fname]')
          ON DUPLICATE KEY UPDATE first_name = '$value[fname]'&quot;;

          $result = mysql_query($query);

          if(!$result){

                    print(&quot;Problem: &quot; . mysql_error() . &quot;&quot;);
          } else {

                    print(&quot;Success !&quot;);
          }

}
</pre>
<p>Read the manual on this for more information. This snippet will INSERT if a UNIQUE (in this case &#8216;id&#8217;) does not exist. It will UPDATE any existing unique. In this case any existing &#8216;id&#8217;s, the &#8216;first_name&#8217; column will get updated. </p>
<p>One could also use the <b><a href="http://dev.mysql.com/doc/refman/5.0/en/replace.html">REPLACE</a></b> function. As I understand the difference, REPLACE will DELETE any matching uniques, and INSERT a new record in it&#8217;s place.</p>
<p>Comments? Better ways? I&#8217;m always up for learning something new so please chime in ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2007/12/20/mysql-conditional-insert/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php: Installing imagick extension on WindowsXP</title>
		<link>http://www.beginnercode.com/2007/10/12/php-installing-imagick-extension-on-windowsxp/</link>
		<comments>http://www.beginnercode.com/2007/10/12/php-installing-imagick-extension-on-windowsxp/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 16:39:40 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/index.php/2007/10/12/php-installing-imagick-extension-on-windowsxp/</guid>
		<description><![CDATA[This may seem simple enough to many programmers out there but this threw me for a few days. This is how you install imagick on a windows server. If your site is on a shared host, you need to ask your host to install the extension for you.
For this example I am running php 5.2.4 [...]]]></description>
			<content:encoded><![CDATA[<p>This may seem simple enough to many programmers out there but this threw me for a few days. This is how you install imagick on a windows server. If your site is on a shared host, you need to ask your host to install the extension for you.</p>
<p>For this example I am running <a href="http://www.php.net/">php</a> 5.2.4 on <a href="http://www.aprelium.com/">Abyss</a>/Apache web server</p>
<p>Download the matching pecl5 Binary <a href="http://www.php.net/downloads.php">from php.net</a>. In this case its pecl5.2-win32-200710121230.zip (matching my current php version).</p>
<p>Unpack the file.</p>
<p>Copy the php&#95;imagick.dll into php/ext/ directory</p>
<p><img src='http://www.beginnercode.com/wp-content/imgupload/2007/10/addphpextension_dll.jpg' alt='php pecl dll' /></p>
<p>Open your php.ini file and look for the &#8220;Dynamic Extensions&#8221; area. In there will be a list of items (some commented out). Add the following line to the bottom of the list: extension=php&#95;imagick.dll</p>
<p><img src='http://www.beginnercode.com/wp-content/imgupload/2007/10/addphpextension_ini.jpg' alt='Add the extension to your ini' /></p>
<p>Save the changes you made.</p>
<p>Restart your web server.</p>
<p>If these steps were successful imagick will show up on any php page using the phpinfo() function.</p>
<p><img src='http://www.beginnercode.com/wp-content/imgupload/2007/10/imagickphpinfo.jpg' alt='imagick in the phpinfo()' /></p>
<p><tags>imagick, pecl-extension, php-extension</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2007/10/12/php-installing-imagick-extension-on-windowsxp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php: Whats your commenting style?</title>
		<link>http://www.beginnercode.com/2007/08/14/php-whats-your-commenting-style/</link>
		<comments>http://www.beginnercode.com/2007/08/14/php-whats-your-commenting-style/#comments</comments>
		<pubDate>Tue, 14 Aug 2007 15:26:42 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/index.php/2007/08/14/php-whats-your-commenting-style/</guid>
		<description><![CDATA[I was writing up a few scripts and as I was adding my commenting I noticed I tend to comment differently depending on the difficulty of the script and how many different parts or procedures there are to it. I don&#8217;t have a set convention, but I suppose as with all things it would make [...]]]></description>
			<content:encoded><![CDATA[<p>I was writing up a few scripts and as I was adding my commenting I noticed I tend to comment differently depending on the difficulty of the script and how many different parts or procedures there are to it. I don&#8217;t have a set convention, but I suppose as with all things it would make things easier on myself and others if I had some kind of standardization&#8230;</p>
<p>For larger &#8216;areas&#8217; that contain functions or a series of procedures that extract or parse sections of data I&#8217;m now starting with this:</p>
<pre class="brush: php;">
/***
*
* This is a comment.
* Here I leave notes about the section and what it does.
* I may also include notes to myself here.
* Note: This could probably be done more eficiently
*
*/
</pre>
<p>
As there are more breakdowns within these sections I&#8217;m using this:</p>
<pre class="brush: php;">
/*  [ Parse out the text file ]  */
</pre>
<p>
And further drilled down I use the more inline commenting</p>
<pre class="brush: php;">
/*  [ Print data]  */

$parts = explode(&quot;|&quot;, $the_array); // get the parts

$color = false; // set color var for shading every other row

print(&quot;&lt;table&gt;&quot;); 

// loop through data &amp; print
foreach($parts as $key =&gt; $row){ 

    // CSS Note: shading &lt;tr&gt;'s with css mostly works with nice browsers
    // For IE 6+ one needs to shade the &lt;td&gt;'s

    if($color){
        print(&quot;&lt;tr class=\&quot;rowColor1\&quot;&gt; &quot;); // start row with color 1
        $color = !$color; // unset the color so it alternates next loop
    } else {
        print(&quot;&lt;/tr&gt;&lt;tr class=\&quot;rowColor2\&quot;&gt; &quot;); // start row with color 2
        $color = true; // set the color so it alternates next loop
    }

    print(&quot;&lt;td&gt;$row[first_name]&lt;/td&gt;&lt;/tr&gt;&quot;); // print cell data and close the row
}

print(&quot;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&quot;);
</pre>
<p>The inline comments still seem a bit &#8216;messy&#8217; to me. But for now it will work.</p>
<p>One of the reasons I decided to standardize is because even with commenting and extra line spaces in the scripts it was still difficult to sort out what exactly was going on. Another thing that tripped my thought was having a glance at <a href="http://www.phpdoc.org/">phpDocumentor</a>. It seems to function on how you comment your code. I did try to install it but for some reason it was way over my head. It looks like a neat tool but I rarely seem to write more than 4 different files and those are often less than 300-400 lines. </p>
<p>I&#8217;ve yet to test it in comments but my plugin to allow code viewing is much like bbc code. &#91;code lang=&#34;php&#34;&#93; // comment  &#91;&#47;code&#93;</p>
<p>So whats your style? Is there a standard? What have you seen that looks the cleanest? Leave a comment&#8230; with some comments ;-)</p>
<p><b><u>Update 12/3/07</u></b> Elizabeth Naramore has written a <a href="http://shiflett.org/blog/2007/dec/php-advent-calendar-day-2">nice article</a> on the effectiveness of comments in your code over at the Chris Shiflett blog. It&#8217;s a great read on WHY commenting is good in your code.</p>
<p><tags>php, comment, code, script, php+script, php+comment</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2007/08/14/php-whats-your-commenting-style/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My Favorite Dev Tools</title>
		<link>http://www.beginnercode.com/2007/03/08/my-favorite-dev-tools/</link>
		<comments>http://www.beginnercode.com/2007/03/08/my-favorite-dev-tools/#comments</comments>
		<pubDate>Thu, 08 Mar 2007 22:03:07 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=122</guid>
		<description><![CDATA[I&#8217;ve recently reformatted my computer and started missing my favorite dev tools. In an attempt to record them, I can also share them with others.
A list of my current favorite web tools&#8230;
Text Editor:

Notepad 2 &#8211; Very Light. Very Simple.

Compression Utility:

IZARC &#8211; IMO, better than winzip

Localhost Server (Apache/mySQL):

Wamp &#8211; Run an Apache web server on your [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently reformatted my computer and started missing my favorite dev tools. In an attempt to record them, I can also share them with others.</p>
<p>A list of my current favorite web tools&#8230;</p>
<p><u><b>Text Editor:</b></u>
<ul>
<li><a href="http://www.flos-freeware.ch/notepad2.html">Notepad 2</a> &#8211; Very Light. Very Simple.</li>
</ul>
<p><u><b>Compression Utility:</b></u>
<ul>
<li><a href="http://www.izarc.org/">IZARC</a> &#8211; IMO, better than winzip</li>
</ul>
<p><u><b>Localhost Server (Apache/mySQL):</b></u>
<ul>
<li><a href="http://www.wampserver.com/en/">Wamp</a> &#8211; Run an Apache web server on your PC. You can configure it to run or not run on startup. It also includes mySQl and a few php extensions.</li>
</ul>
<p><u><b>Firefox extensions:</b></u>
<ul>
<li><a href="https://addons.mozilla.org/firefox/539/">measureit</a> &#8211; Measure pixels right on your screen.</li>
<li><a href="https://addons.mozilla.org/firefox/271/">colorzilla</a> &#8211; Grab colors off of web pages, zoom, and built in color picker.</li>
<li><a href="https://addons.mozilla.org/firefox/60/">web developer</a> &#8211; CSS, XHTML, Screen resize, line guides, disable styles and much much more.</li>
<li><a href="https://addons.mozilla.org/firefox/1843/">firebug</a> &#8211; A great tool especially for pages created in php. You may have 100 lines of code before the html begins. This helps you debug xhtml issues on &#8220;line 12&#8243; which is actually line 112. Works well with included php files as well.</li>
</ul>
<p><u><b>IE Explorer Add On:</b></u>
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=e59c3964-672d-4511-bb3e-2d5e1db91038&#038;displaylang=en">IE Dev Toolbar</a>(For IE Similar to Firebug)</li>
<p><tags>Tools, Dev, Developer, Dev Tools</tags></ul>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2007/03/08/my-favorite-dev-tools/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ODBC Viewer</title>
		<link>http://www.beginnercode.com/2007/02/28/odbc-viewer/</link>
		<comments>http://www.beginnercode.com/2007/02/28/odbc-viewer/#comments</comments>
		<pubDate>Wed, 28 Feb 2007 18:56:09 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=121</guid>
		<description><![CDATA[I had recently been peeking into a SQL database via Microsoft Access. I got quite used to browsing all the tables and fields, seeing their data types, and visually seeing their relationships. I&#8217;ve just began a project that connects to a proprietary(aged) database that uses ODBC to connect to it. Access would not allow me [...]]]></description>
			<content:encoded><![CDATA[<p>I had recently been peeking into a SQL database via Microsoft Access. I got quite used to browsing all the tables and fields, seeing their data types, and visually seeing their relationships. I&#8217;ve just began a project that connects to a proprietary(aged) database that uses ODBC to connect to it. Access would not allow me to view this the same (At least I couldn&#8217;t figure it out).</p>
<p>After a quick search I found a freeware application called <a href="http://passportodbc.embassy-software-inc.qarchive.org/">passportODBC</a>(You can download from <a href="http://www.google.com/search?source=ig&#038;hl=en&#038;q=passportODBC&#038;btnG=Google+Search">other locations/ sites</a>). It does require some information from you to register it. Some basic info like your name, and email and a phone number.</p>
<p><center><a style="border:none;" href="http://www.beginnercode.com/wp-content/imgupload/passport.jpg"><img src="http://www.beginnercode.com/wp-content/imgupload/_passport.jpg" width="250" height="146" alt="passportODBC" title="passportODBC"  /></a></center></p>
<p>It&#8217;s not as fast as access and SQL server 2005, but I&#8217;m suspecting a lot of that has to do that it is ODBC. It&#8217;s really quite simple to use. Choose your data source, enter some credentials and go. You can view tables, all the fields, and the field attributes.</p>
<p><tags>ODBC, programming, database</tags></p>
<p><b>Update 2/28/07 1:20PM</b><br />
Embassy Software offers the download <a href="http://www.edi-software.net/news3.html">direct from their site</a>.</p>
<p><b>Update 5/16/07</b><br />
I found a more simple tool for viewing via ODBC. You can compose queries and the likes. It&#8217;s much more simple to use (for me anyways) <b>ODBC View</b> can be downloaded from <a href="http://www.sliksoftware.co.nz/">sliksoftware.co.nz</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2007/02/28/odbc-viewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REGEX Library</title>
		<link>http://www.beginnercode.com/2006/03/09/regex-library/</link>
		<comments>http://www.beginnercode.com/2006/03/09/regex-library/#comments</comments>
		<pubDate>Thu, 09 Mar 2006 19:23:13 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php Snippets]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=91</guid>
		<description><![CDATA[I was working up a form and needed to come up with an email regex. I know by now I probably should have my own regex library, or even be able to write my own &#8211; but I haven&#8217;t exercised my regex skills enough. Often time doesn&#8217;t allow an extensive learning period when your already [...]]]></description>
			<content:encoded><![CDATA[<p>I was working up a form and needed to come up with an email regex. I know by now I probably should have my own regex library, or even be able to write my own &#8211; but I haven&#8217;t exercised my regex skills enough. Often time doesn&#8217;t allow an extensive learning period when your already half way through creating a form! </p>
<p>I came across this great <a href="http://regexlib.com/default.aspx">regex library at regexlib.com</a>. It&#8217;s searchable, offers on the fly tests of user contibuted regular expresssions, rss feeds of recently added patterns, and contains a <a href="http://regexlib.com/CheatSheet.aspx">Cheat Sheet</a> for regex reference.</p>
<p>Of course, programmer beware. Be careful copying and pasting code. And definately test that code before you implement it.</p>
<p><tags>regex, php</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2006/03/09/regex-library/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>php: syntax woes</title>
		<link>http://www.beginnercode.com/2006/01/03/php-syntax-woes/</link>
		<comments>http://www.beginnercode.com/2006/01/03/php-syntax-woes/#comments</comments>
		<pubDate>Tue, 03 Jan 2006 22:40:02 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=73</guid>
		<description><![CDATA[Today I fought what I thought was some kind of permissions error. I was learning how to create a database table in mySQL with php.
After 3 hours I figured out my error was due to syntax.
&#8220;AUTO-INCREMENT&#8221; is not the same as &#8220;AUTO_INCREMENT&#8221;
I looked over that line at least a thousand times thinking &#8211;  thats [...]]]></description>
			<content:encoded><![CDATA[<p>Today I fought what I thought was some kind of permissions error. I was learning how to create a database table in mySQL with php.</p>
<p>After 3 hours I figured out my error was due to syntax.<br />
&#8220;AUTO-INCREMENT&#8221; is not the same as &#8220;AUTO_INCREMENT&#8221;</p>
<p>I looked over that line at least a thousand times thinking &#8211;  thats right.</p>
<p>When you are trouble shooting code:<br />
Break down the elements.<br />
Print out the variables  print_r();<br />
Put in escape messages while you are creating:</p>
<pre class="brush: php;">
if($this_is_true){
  print(&quot;Its all good&lt;br /&gt;&quot;);
} else {
  print(&quot;Houston, we've got a problem&quot;);
}
</pre>
<p>or print all the elements getting $_POSTED:
<pre class="brush: php;">
print_r($_POST);
</pre>
<p>or print all the elements in an array:
<pre class="brush: php;">
print_r($myArray);
</pre>
<p>&#8230;it only takes a few seconds to code that temporarily in to your code to help find problems.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2006/01/03/php-syntax-woes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php: Dynamically fill a select box</title>
		<link>http://www.beginnercode.com/2005/12/30/php-dynamically-fill-a-select-box/</link>
		<comments>http://www.beginnercode.com/2005/12/30/php-dynamically-fill-a-select-box/#comments</comments>
		<pubDate>Fri, 30 Dec 2005 22:20:54 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=72</guid>
		<description><![CDATA[One way to fill a select box with array elements.

&#60;html&#62;
&#60;head&#62;
&#60;title&#62;Select Box&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;

&#60; ?php
$myArray = array('cat' , 'dog' , 'mouse' , 'cow');
?&#62;

&#60;select name=&#34;myselect&#34;&#62;
&#60;option value=&#34;&#34;&#62;&#60;/option&#62; // Sets blank entry *optional*
&#60; ?php
foreach($myArray as $value){ // Loop through each element
  print(&#34;&#60;option value=\&#34;$value\&#34;&#62;$value&#60;option&#62;&#34;);
}
?&#62;
&#60;/option&#62;&#60;/select&#62;

&#60;/body&#62;
&#60;/html&#62;

php, select, drop down
]]></description>
			<content:encoded><![CDATA[<p>One way to fill a select box with array elements.</p>
<pre class="brush: php;">
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Select Box&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt; ?php
$myArray = array('cat' , 'dog' , 'mouse' , 'cow');
?&gt;

&lt;select name=&quot;myselect&quot;&gt;
&lt;option value=&quot;&quot;&gt;&lt;/option&gt; // Sets blank entry *optional*
&lt; ?php
foreach($myArray as $value){ // Loop through each element
  print(&quot;&lt;option value=\&quot;$value\&quot;&gt;$value&lt;option&gt;&quot;);
}
?&gt;
&lt;/option&gt;&lt;/select&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><tags>php, select, drop down</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2005/12/30/php-dynamically-fill-a-select-box/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>php:  Save browsed page as $var and send using phpMailer</title>
		<link>http://www.beginnercode.com/2005/12/28/php-save-browsed-page-as-var-and-send-using-phpmailer/</link>
		<comments>http://www.beginnercode.com/2005/12/28/php-save-browsed-page-as-var-and-send-using-phpmailer/#comments</comments>
		<pubDate>Wed, 28 Dec 2005 17:53:08 +0000</pubDate>
		<dc:creator>^Lestat</dc:creator>
				<category><![CDATA[Computing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.beginnercode.com/?p=69</guid>
		<description><![CDATA[You can store an entire page as if it were opened in a browser, including all dynamic
data. Here&#8217;s how&#8230;
(Please use caution copying/pasting. Quotes can be a problem with the current plugin)
For this example we are going to build a form and the results using phpMailer in an html format: 
form.php
results.php
preview.php
sendmail.php
form.php:

&#60; ?php
//Start a session
session_start();
header(&#34;Cache-control: private&#34;); // [...]]]></description>
			<content:encoded><![CDATA[<p>You can store an entire page as if it were opened in a browser, including all dynamic<br />
data. Here&#8217;s how&#8230;</p>
<p>(Please use caution copying/pasting. Quotes can be a problem with the current plugin)<br />
For this example we are going to build a form and the results using <a href="http://phpmailer.sourceforge.net/">phpMailer</a> in an html format: </p>
<p>form.php<br />
results.php<br />
preview.php<br />
sendmail.php</p>
<p>form.php:</p>
<pre class="brush: php;">
&lt; ?php
//Start a session
session_start();
header(&quot;Cache-control: private&quot;); // IE 6 Fix.
?&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Form&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;form method=&quot;POST&quot; action=&quot;preview.php&quot;&gt;
First Name: &lt;input type=&quot;text&quot; name=&quot;fName&quot; value=&quot;&lt;?php print(&quot;$_SESSION[fName]&quot;); ?/&gt;&quot; /&gt;
&lt;br /&gt;
Last Name: &lt;input type=&quot;text&quot; name=&quot;lName&quot;value=&quot;&lt;?php print(&quot;$_SESSION[lName]&quot;); ?/&gt;&quot; /&gt;
&lt;input type=&quot;submit&quot; name=&quot;submitButton&quot;  value=&quot;submit&quot; /&gt;
&lt;/form&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>preview.php:</p>
<pre class="brush: php;">
&lt; ?php
//Start a session
session_start();
header(&quot;Cache-control: private&quot;); // IE 6 Fix.
?&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Your Results&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;

&lt; ?php
include(&quot;results.php&quot;);
?&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>results.php:</p>
<pre class="brush: php;">
&lt; ?php
//Start a session
session_start();
header(&quot;Cache-control: private&quot;); // IE 6 Fix.
?&gt;

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;style type=&quot;text/css&quot;&gt;
.firstname{
  font: 12px verdana green;
}

.lastname{
  font: 14px arial red;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt; ?php print(&quot;&lt;p class=\&quot;firstname\&quot;&gt;Hello $fName&quot;); ?&gt;
&lt; ?php print(&quot;&lt;p class=\&quot;lastname\&quot;&gt;Your last name is $fName&quot;); ?&gt;

&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>And now the sendmail.php and gathering the output in a $var:</p>
<pre class="brush: php;">
&lt; ?php
//Start a session
session_start();
header(&quot;Cache-control: private&quot;); // IE 6 Fix.

// call the mail class
require(&quot;class.phpmailer.php&quot;);
$mail = new PHPMailer();

// Set mail headers &amp; connection
$mail-&gt;IsSMTP(); // tell phpMailer were using smtp
$mail-&gt;Host = &quot;smtp.server.com&quot;; // SMTP server
$mail-&gt;SMTPAuth =true; // turn on smtp auth
$mail-&gt;Username = &quot;mail@domain.com&quot;; //smtp username
$mail-&gt;Password = &quot;password&quot;; //smtp password
$mail-&gt;From = &quot;user@domain.com&quot;;
$mail-&gt;FromName = &quot;$fName&quot;;
$mail-&gt;AddAddress(&quot;fromAddress@domain.com&quot;); // From address

$mail-&gt;Subject = &quot;Form Results&quot;;
$mail-&gt;IsHTML(true); // tell phpMailer we're sending html email

// *** Grab Output Of HTML File as if it were opened in browser ***
ob_start();
include(&quot;results.php&quot;);
$htmlbody = ob_get_contents(); // adding output to the variable
ob_end_clean();

// *** Set the htmlbody variable in the email ***
$mail-&gt;Body = &quot;$htmlbody&quot;;

// return results
if(!$mail-&gt;Send()){
	print(&quot;Mail was NOT sent&lt;br /&gt;&quot;);
	print(&quot;Mailer Error: &quot; . $mail-&gt;ErrorInfo );
} else {
	print(&quot;Thank you. Your mail was sent.&quot;);
?&gt;
</pre>
<p>The following code is what grabs the output as if it were opened in a browser. The mail form was just an example. I&#8217;m sure there are other uses for this.</p>
<pre class="brush: php;">
// *** Grab Output Of HTML File as if it were opened in browser ***
ob_start();
include(&quot;results.php&quot;);
$htmlbody = ob_get_contents(); // adding output to the variable
ob_end_clean();
</pre>
<p>Comments? Suggestions? See errors that should be changed? Feel free to comment.</p>
<p><tags>phpMailer, php html email, php email, php get contents, php form data</tags></p>
]]></content:encoded>
			<wfw:commentRss>http://www.beginnercode.com/2005/12/28/php-save-browsed-page-as-var-and-send-using-phpmailer/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
