<?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>gHacks technology news &#187; php</title>
	<atom:link href="http://www.ghacks.net/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghacks.net</link>
	<description>A technology blog covering software, mobile phones, gadgets, security, the Internet and other relevant areas.</description>
	<lastBuildDate>Sun, 08 Nov 2009 22:45:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Apache troubleshooting tips</title>
		<link>http://www.ghacks.net/2009/11/08/apache-troubleshooting-tips/</link>
		<comments>http://www.ghacks.net/2009/11/08/apache-troubleshooting-tips/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 00:21:57 +0000</pubDate>
		<dc:creator>Jack Wallen</dc:creator>
				<category><![CDATA[Advice]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networks]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[The Web]]></category>
		<category><![CDATA[Tutorials Basic]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache log]]></category>
		<category><![CDATA[apache2]]></category>
		<category><![CDATA[apache2ctl]]></category>
		<category><![CDATA[log files]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=18266</guid>
		<description><![CDATA[How many times have you installed a LAMP server only to find Apache doesn&#8217;t seem to want to run right? Or you install a new module only to see Apache try to download pages as file, instead of displaying them on screen?
There are a hundred and one thousand things that can go wrong with any [...]]]></description>
			<content:encoded><![CDATA[<p>How many times have you installed a LAMP server only to find Apache doesn&#8217;t seem to want to run right? Or you install a new module only to see Apache try to download pages as file, instead of displaying them on screen?</p>
<p>There are a hundred and one thousand things that can go wrong with any web server installation. From a fresh installation to an installation that has been running for a long time, you never know when something is going to cause your web server to go astray. When it does happen, it&#8217;s always nice to know that, usually, Occam&#8217;s Razor applies.</p>
<p>In this tutorial you will find some advice that will help you through some of the more common issues that can pop up with an Apache web server.</p>
<p><span id="more-18266"></span><strong>Is your server actually running?</strong></p>
<p>Believe it or not, this has happened to plenty of administrators. You take the server down, do some maintenance, and when you go to check out the server you&#8217;re getting errors. The first thing you do, naturally, is check out that <strong>/etc/apache2/apache.conf</strong> file to make sure your syntax is correct. But it&#8217;s perfect! What&#8217;s up? The first thing you might want to check is to make sure the server is running. But you don&#8217;t want to just issue the command to start the server or reload the server. Instead, issue the command:</p>
<p><em>sudo /etc/init.d/apache2 status</em></p>
<p>Which should return something like:</p>
<p><em>* apache is running (pid 9751).</em></p>
<p>If not, start the server with either:</p>
<p><em>sudo /etc/init.d/apache2 start</em></p>
<p>or</p>
<p><em>sudo apache2ctl start</em></p>
<p>NOTE: If you are using a distribution like Fedora, SuSE, or Mandriva you will need to first <em>su </em>to the root user and issue the above commands WITHOUT using <em>sudo</em>.</p>
<p><strong>It&#8217;s not running and it won&#8217;t start</strong></p>
<p>Did you just make changes to your Apache configuration file? Are the changes correct? If you&#8217;re not sure, you can use the <em>apache2ctl </em>command to check the syntax of your configuration file. This is done with the command:</p>
<p><em>sudo apache2ctl configtext</em></p>
<p><em><span style="font-style: normal">The above command should report:</span></em></p>
<p><em><span style="font-style: normal">Syntax OK</span></em></p>
<p><em><strong><span style="font-style: normal"><span style="font-weight: normal">If you don&#8217;t get an OK, you will get information that points to the errors in your configuration file. </span></span></strong></em></p>
<p><em><strong><span style="font-style: normal"><span style="font-weight: normal"><strong>Apache wants to download .php files!</strong></span></span></strong></em></p>
<p><em><strong><span style="font-style: normal"><span style="font-weight: normal"><strong><span style="font-weight: normal">This is another common issue. When you add a new tool on your web server (such as Drupal), if your configuration file is set up properly, any .php file might not be displayed. Instead any attempt to view a .php file will instead have your browser trying to download the file. Why is this? Apache must be informed that certain extensions are to be displayed, not downloaded. This is done from within the Apache configuration file. Open up that file (in the Ubuntu server it will be </span>/etc/apache2/apache2.conf<span style="font-weight: normal">) and first look for the following line:</span></strong></span></span></strong></em></p>
<p><em><strong><span style="font-weight: normal"><strong><span style="font-weight: normal">DirectoryIndex index.html</span></strong></span></strong></em></p>
<p>If that file doesn&#8217;t include <em>index.php </em>nearly all sites that use php will be rendered useless.</p>
<p>The second line to look for is:</p>
<p><em>AddHandler application/x-httpd-php .php</em></p>
<p>If you find this line, and it is commented out, make sure you uncomment it by removing the &#8220;#&#8221; character. If it is not there add it to the bottom of the configuration file.</p>
<p>And, as always, when you make a change to the configuration file, restart Apache.</p>
<p><strong>Know where to look for problems</strong></p>
<p>Finally, it is crucial that you know where to first turn when the above doesn&#8217;t help you out. Any time I have an issue with Apache where Occam&#8217;s Razor does not apply, the first place I turn is the log files.</p>
<p>If you look in <strong>/var/log/apache2</strong> you will find, at least, the following files:</p>
<ul>
<li><span style="background-color: #ffffff">access.log: This keeps track of any connection made to your server.</span></li>
<li><span style="background-color: #ffffff">error.log: This keeps track of any errors that occur with Apache.</span></li>
<li><span style="background-color: #ffffff">other_vhosts_access.log: This is where virtual hosts will log when the virtual host has not been prescribed its own log file.</span></li>
</ul>
<p>Of course, as your site evolves so will your available log files. Regardless of what you find in <strong>/var/log/apache2</strong>, that is where you should always first turn when you have problems. Even before you google.</p>
<p><strong>Final thoughts</strong></p>
<p>Now you should be able to handle some of the more common issues with the Apache server. And if your problem isn&#8217;t common, you also know where to turn to find clues that will lead you down the right path to correction.</p>
<p><em><strong><span style="font-style: normal"><span style="font-weight: normal"><strong><span style="font-weight: normal"> </span><br />
</strong></span></span></strong></em></p>

	Tags: <a href="http://www.ghacks.net/tag/apache/" title="apache" rel="tag">apache</a>, <a href="http://www.ghacks.net/tag/apache-log/" title="apache log" rel="tag">apache log</a>, <a href="http://www.ghacks.net/tag/apache2/" title="apache2" rel="tag">apache2</a>, <a href="http://www.ghacks.net/tag/apache2ctl/" title="apache2ctl" rel="tag">apache2ctl</a>, <a href="http://www.ghacks.net/tag/log-files/" title="log files" rel="tag">log files</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2008/12/28/portable-web-server/" title="Portable Web Server (December 28, 2008)">Portable Web Server</a> (8)</li>
	<li><a href="http://www.ghacks.net/2009/09/17/local-apache-web-server-wampserver/" title="Local Apache Web Server Wampserver (September 17, 2009)">Local Apache Web Server Wampserver</a> (3)</li>
	<li><a href="http://www.ghacks.net/2009/07/23/how-to-install-a-lamp-server/" title="How to: Install a LAMP server (July 23, 2009)">How to: Install a LAMP server</a> (6)</li>
	<li><a href="http://www.ghacks.net/2007/01/31/host-your-own-webserver/" title="Host your own webserver (January 31, 2007)">Host your own webserver</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/" title="Wordpress template tags you should know (March 29, 2009)">Wordpress template tags you should know</a> (4)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/11/08/apache-troubleshooting-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Local Apache Web Server Wampserver</title>
		<link>http://www.ghacks.net/2009/09/17/local-apache-web-server-wampserver/</link>
		<comments>http://www.ghacks.net/2009/09/17/local-apache-web-server-wampserver/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 09:08:17 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache server]]></category>
		<category><![CDATA[apache web server]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wampserver]]></category>
		<category><![CDATA[webmaster]]></category>
		<category><![CDATA[xampp]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=16430</guid>
		<description><![CDATA[Running a local Apache web server is essential for many webmasters. It is always a good idea to test code locally before publishing it on the Internet. Professional webmasters usually test their code in a local web server before it gets published. Mainly to avoid possible downtimes in the live environment but also to avoid [...]]]></description>
			<content:encoded><![CDATA[<p>Running a local Apache web server is essential for many webmasters. It is always a good idea to test code locally before publishing it on the Internet. Professional webmasters usually test their code in a local web server before it gets published. Mainly to avoid possible downtimes in the live environment but also to avoid the hassle of having to upload and edit code on the Internet or network. It&#8217;s simply faster to test everything locally.</p>
<p>Wampserver is an Apache web server for the Windows operating system. It provides in many regards the same functionality of other web server solutions like <a href="http://www.ghacks.net/2007/01/31/host-your-own-webserver/">XAMPP</a> or <a href="http://www.ghacks.net/2009/03/28/home-web-server/">Home Web Server</a> which we have reviewed in the past. The latest version of the local web server package will install Apache 2.2.11, MySQL 5.1.36 and PHP 5.3.0 on the local computer system.</p>
<p><span id="more-16430"></span>One interesting unique feature is the ability to add different versions of Apache, MySQL and PHP to the installation in the form of add-ons. This can be very handy to test a website locally under multiple different Apache, MySQL or PHP release versions.</p>
<p><img src="http://www.ghacks.net/wp-content/uploads/2009/09/apache_web_server.gif" alt="apache web server" title="apache web server" width="281" height="289" class="alignnone size-full wp-image-16431" /></p>
<p>The installation of Wampserver will always install the latest versions of Apache, MySQL and PHP. One interesting security feature is the ability to limit access to the web server to localhost. It is required to click on the &#8220;put online&#8221; option to make it available to other computer systems as well.</p>
<p>Additional Apache, MySQL and PHP versions can be installed from the Wamp add-ons <a href="http://www.wampserver.com/en/add-ons.php">page</a>. All add-ons are provided as executables that can be installed easily on the operating system.</p>
<p>Webmasters who need to test code offline can use Wampserver to do so. It is especially useful to test code against multiple versions of Apache, MySQL and PHP. Something that the other home server solutions do not provide.</p>
<p><a href="http://www.wampserver.com/en/">Wampserver</a> is Open Source and can be downloaded from the developer&#8217;s website.</p>

	Tags: <a href="http://www.ghacks.net/tag/apache/" title="apache" rel="tag">apache</a>, <a href="http://www.ghacks.net/tag/apache-server/" title="apache server" rel="tag">apache server</a>, <a href="http://www.ghacks.net/tag/apache-web-server/" title="apache web server" rel="tag">apache web server</a>, <a href="http://www.ghacks.net/tag/mysql/" title="mysql" rel="tag">mysql</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/wampserver/" title="wampserver" rel="tag">wampserver</a>, <a href="http://www.ghacks.net/tag/webmaster/" title="webmaster" rel="tag">webmaster</a>, <a href="http://www.ghacks.net/tag/xampp/" title="xampp" rel="tag">xampp</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2008/12/28/portable-web-server/" title="Portable Web Server (December 28, 2008)">Portable Web Server</a> (8)</li>
	<li><a href="http://www.ghacks.net/2009/07/23/how-to-install-a-lamp-server/" title="How to: Install a LAMP server (July 23, 2009)">How to: Install a LAMP server</a> (6)</li>
	<li><a href="http://www.ghacks.net/2007/01/31/host-your-own-webserver/" title="Host your own webserver (January 31, 2007)">Host your own webserver</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/" title="Web Development: Standardizing variables to code faster (January 2, 2009)">Web Development: Standardizing variables to code faster</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/09/17/local-apache-web-server-wampserver/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to: Install a LAMP server</title>
		<link>http://www.ghacks.net/2009/07/23/how-to-install-a-lamp-server/</link>
		<comments>http://www.ghacks.net/2009/07/23/how-to-install-a-lamp-server/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 17:43:55 +0000</pubDate>
		<dc:creator>Jack Wallen</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Networks]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[Tutorials Basic]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[lamp server]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tasksel]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=14678</guid>
		<description><![CDATA[If you&#8217;ve read enough of my Ghacks tutorials you have most likely come across mention of a LAMP server. If you are not sure what a LAMP server is:

Linux
Apache
MySQL
P (can mean PHP or PERL &#8211; depends upon your needs)

LAMP servers are very popular, cheap, effective, flexible, and reliable servers. But how are they installed? Actually, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve read enough of my Ghacks tutorials you have most likely come across mention of a LAMP server. If you are not sure what a LAMP server is:</p>
<ul>
<li>Linux</li>
<li>Apache</li>
<li>MySQL</li>
<li>P (can mean PHP or PERL &#8211; depends upon your needs)</li>
</ul>
<p>LAMP servers are very popular, cheap, effective, flexible, and reliable servers. But how are they installed? Actually, it&#8217;s not that hard. In this tutorial I am going to show you how to install a LAMP in two different ways: From the command line (using separate tools) and using the <em>tasksel</em> tool.</p>
<p><span id="more-14678"></span><strong>Hardware needed</strong></p>
<p>Fortunately a LAMP server can be installed on lower-end hardware and still serve as a fairly efficient server. Naturally if you are going to be using your LAMP server for high traffic, you will want to select your hardware wisely.</p>
<p><strong>Install prerequisite</strong></p>
<p>Before you begin the installation of your server you will need to have your operating system installed. This is the &#8220;L&#8221; of LAMP. So find your favorite Linux distribution and install the operating system. For the purposes of this installation I am going to be installing on a Ubuntu 9.04 server installation. This will be a console only server (no GUI desktop) which is fine because the installation is done via command line only.</p>
<p>Once you have your operating system installed you are ready to install your server.</p>
<p><strong>Apache</strong></p>
<p>This is the easiest portion to install. Either log in to your console or open up a terminal window (if you are working from a GUI desktop) and enter the following command:<br />
<code>sudo apt-get install apache2</code></p>
<p>You will have to enter your sudo user password for this installation to continue. Once this installation is complete check it by pointing a browser to that server IP address. You should instantly know if Apache is up and running.</p>
<p><strong>PHP</strong></p>
<p>For the purposes of this article we will assume the &#8220;P&#8221; stands for PHP. To install PHP (and all of its requirements) issue the command:</p>
<p><code>sudo apt-get install php5 libapache2-mod-php5</code></p>
<p>Once this installation is complete restart Apache with the command:</p>
<p><code>sudo /etc/init.d/apache2 restart</code></p>
<p>Let&#8217;s make sure this portion works properly. To test this create a file in the Apache document root (for this install it will be <strong>/var/www</strong>) called test.php. The contents of this file will be:<br />
<code>&lt; ?php phpinfo(); ?&gt;</code></p>
<p>Save that file and then point your browser to http://IP_ADDRESS/test.php</p>
<p>Where IP_ADDRESS is the actual IP address of your server.</p>
<p>You should see &#8220;Test PHP Page&#8221; written on your browsers page. If so, you&#8217;re good to go.</p>
<p><strong>MySQL</strong></p>
<p>Now to install MySQL. To do this issue the command:</p>
<p><code>sudo apt-get install mysql-server</code></p>
<p>Once this is done you then need to set a password for MySQL. To do this issue the command:</p>
<p><code>mysql -u root</code></p>
<p>which will put you in the MySQL prompt. From this prompt (which looks like <em>mysql&gt; </em>) enter the command:<br />
<code>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('YOURPASSWORD');</code></p>
<p>Where YOURPASSWORD is the password you want to use for the mysql user.</p>
<p>Now start your MySQL server with the command:</p>
<p><code>/etc/init.d/mysql start</code></p>
<p>That&#8217;s it. Your LAMP server is up and running.</p>
<p><strong>The quick version</strong></p>
<p>You can actually install a full-on LAMP server on a (Ubuntu server install) with a single command:</p>
<p><code>sudo tasksel</code></p>
<p>You will need to select LAMP from the list and you will eventually be prompted for a MySQL password. That&#8217;s it.</p>
<p><strong>Final thoughts</strong></p>
<p>Getting a powerful, flexible web server up and running will take you less time and effort than you think. LAMP servers are an outstanding choice for your web servers&#8217; needs.</p>

	Tags: <a href="http://www.ghacks.net/tag/apache/" title="apache" rel="tag">apache</a>, <a href="http://www.ghacks.net/tag/lamp/" title="LAMP" rel="tag">LAMP</a>, <a href="http://www.ghacks.net/tag/lamp-server/" title="lamp server" rel="tag">lamp server</a>, <a href="http://www.ghacks.net/tag/mysql/" title="mysql" rel="tag">mysql</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/tasksel/" title="tasksel" rel="tag">tasksel</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2008/12/28/portable-web-server/" title="Portable Web Server (December 28, 2008)">Portable Web Server</a> (8)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/09/17/local-apache-web-server-wampserver/" title="Local Apache Web Server Wampserver (September 17, 2009)">Local Apache Web Server Wampserver</a> (3)</li>
	<li><a href="http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/" title="Web Development: Standardizing variables to code faster (January 2, 2009)">Web Development: Standardizing variables to code faster</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/07/23/how-to-install-a-lamp-server/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How To Display Valid Markup Code In Websites</title>
		<link>http://www.ghacks.net/2009/05/07/how-to-display-valid-markup-code-in-websites/</link>
		<comments>http://www.ghacks.net/2009/05/07/how-to-display-valid-markup-code-in-websites/#comments</comments>
		<pubDate>Thu, 07 May 2009 13:19:48 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[html entities]]></category>
		<category><![CDATA[html entities converter]]></category>
		<category><![CDATA[markup code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[valid code]]></category>
		<category><![CDATA[w3c]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=12644</guid>
		<description><![CDATA[There are two difficulties or problems that Internet users encounter when they want to paste code into forms to display these on the Internet. The first problem that can be encountered is that the website will interpret part or all of the code instead of displaying it. A basic example would be to display the [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.ghacks.net/wp-content/uploads/2009/05/w3c.jpg" alt="w3c" title="w3c" width="100" height="86" class="alignleft size-full wp-image-12647" />There are two difficulties or problems that Internet users encounter when they want to paste code into forms to display these on the Internet. The first problem that can be encountered is that the website will interpret part or all of the code instead of displaying it. A basic example would be to display the html code needed to make text linkable on a website. These codes are interpreted by most forms automatically if the user just pastes the code into the form. The second problem that can arise is that the website will not validate because of the way it has been pasted into the form. Displaying the &amp; char will for example return an error when validating the code. This can lead to all kinds of troubles including broken RSS feeds (read: <a href="http://www.ghacks.net/2009/04/14/internet-explorer-8-and-feeds-the-xml-page-cannot-be-displayed/">The XML Feed Cannot Be Displayed</a>).</p>
<p><span id="more-12644"></span>Displaying valid markup code in websites, forums, blogs and any other page is not difficulty. The only thing that needs to be done to achieve this is to convert all entities before pasting the code. This can be done manually or by using a script like that offered at <a href="http://www.spacefem.com/tutorials/makecode.php">Spacefem</a>.</p>
<p>All that needs to be done is to paste the code into the form and click on the Make Code button at the bottom. To display the following code on a website</p>
<p><code>&lt;a href=&quot;http://www.ghacks.net/&quot;&gt;Ghacks&lt;/a&gt;</code></p>
<p>one would have to paste the following code into the form on the website where the code should be displayed</p>
<p><code>&amp;lt;a href=&amp;quot;http://www.ghacks.net/&amp;quot;&amp;gt;Ghacks&amp;lt;/a&amp;gt;</code></p>
<p><img src="http://www.ghacks.net/wp-content/uploads/2009/05/html_entities_converter-500x273.jpg" alt="html entities converter" title="html entities converter" width="500" height="273" class="alignnone size-medium wp-image-12646" /></p>
<p>This is actually the easiest way to ensure that the website will not interpret the code and that the code will be valid markup code.</p>

	Tags: <a href="http://www.ghacks.net/tag/code/" title="code" rel="tag">code</a>, <a href="http://www.ghacks.net/tag/html/" title="html" rel="tag">html</a>, <a href="http://www.ghacks.net/tag/html-entities/" title="html entities" rel="tag">html entities</a>, <a href="http://www.ghacks.net/tag/html-entities-converter/" title="html entities converter" rel="tag">html entities converter</a>, <a href="http://www.ghacks.net/tag/markup-code/" title="markup code" rel="tag">markup code</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/valid-code/" title="valid code" rel="tag">valid code</a>, <a href="http://www.ghacks.net/tag/w3c/" title="w3c" rel="tag">w3c</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/" title="Web Development: How does PHP work? (January 8, 2009)">Web Development: How does PHP work?</a> (21)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/03/04/how-echo-works-in-php/" title="How echo works in PHP (March 4, 2009)">How echo works in PHP</a> (2)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/05/07/how-to-display-valid-markup-code-in-websites/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Display Cached RSS Feed In Your Website</title>
		<link>http://www.ghacks.net/2009/05/06/display-cached-rss-feed-in-your-website/</link>
		<comments>http://www.ghacks.net/2009/05/06/display-cached-rss-feed-in-your-website/#comments</comments>
		<pubDate>Wed, 06 May 2009 11:44:23 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rss feed]]></category>
		<category><![CDATA[simplepie]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[websites]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=12615</guid>
		<description><![CDATA[You might remember the announcement of our new web project Appnews which basically displays software updates in a friendly easily accessible way. What I wanted to do now is to display the five newest items of the RSS feed in the sidebar of this blog to both promote the appnews service but also provide a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.ghacks.net/wp-content/uploads/2009/05/rss.jpg" alt="rss" title="rss" width="128" height="128" class="alignleft size-full wp-image-12614" />You might remember the announcement of our new web project <a href="http://www.appnews.net/">Appnews</a> which basically displays software updates in a friendly easily accessible way. What I wanted to do now is to display the five newest items of the RSS feed in the sidebar of this blog to both promote the appnews service but also provide a new service to my readers as they would be able to see the software updates immediately in the sidebar. What I needed was a high traffic friendly way of displaying the RSS feed and that meant caching. Without caching the script would request the contents on every page hit which would slow down the web server tremendously.</p>
<p><span id="more-12615"></span>One of the better scripts to display cached RSS feeds in a website is SimplePie. It might look a bit intimidating at first glance as it provides lots of options to customize the display. It is however very easy to display a feed with just a few lines of code. Start by downloading <a href="http://simplepie.org/">SimplePie</a> from the website. Extract it to the computer system and upload it to the root folder of the website. You should also create a directory called <em>cache</em> in that root folder and make it writeable (chmod to 777).</p>
<p>Now add the following two lines to the top of the php file where you want to display the feed in. The first line defines the location of the simplepie.inc file on the web server (which is in the simplepie directory in root), the second the feed that you want to display on the website.</p>
<p><code>&lt;?php <br />
include_once $_SERVER['DOCUMENT_ROOT'] . '/simplepie/simplepie.inc'; <br />
$feed = new SimplePie('http://feedproxy.google.com/Ghacksnet');<br />
?&gt;</code></p>
<p>Now place the following code in the location on the website where the feed should be displayed. This will fetch the five newest feed items and display them in the selected location.</p>
<p><code>&lt;ul&gt;<br />
&lt;?php foreach ($feed-&gt;get_items(0, 5) as $item): ?&gt;<br />
    &lt;li&gt;<br />
        &lt;a href=&quot;&lt;?php print $item-&gt;get_permalink(); ?&gt;&quot;&gt;<br />
        &lt;?php print $item-&gt;get_title(); ?&gt;&lt;/a&gt;<br />
    &lt;/li&gt;<br />
&lt;?php endforeach; ?&gt;<br />
&lt;/ul&gt;</code></p>
<p>And that&#8217;s it. SimplePie offers a wealth of additional functions and settings to display more than one feed or mix feeds. The default caching time is 60 minutes.</p>

	Tags: <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/rss-feed/" title="rss feed" rel="tag">rss feed</a>, <a href="http://www.ghacks.net/tag/simplepie/" title="simplepie" rel="tag">simplepie</a>, <a href="http://www.ghacks.net/tag/web-dev/" title="web dev" rel="tag">web dev</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a>, <a href="http://www.ghacks.net/tag/websites/" title="websites" rel="tag">websites</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/03/16/web-development-roundup/" title="Web development roundup (March 16, 2009)">Web development roundup</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
	<li><a href="http://www.ghacks.net/2008/10/26/publish-rss-news-feeds-on-twitter/" title="Publish RSS News Feeds On Twitter (October 26, 2008)">Publish RSS News Feeds On Twitter</a> (6)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/05/06/display-cached-rss-feed-in-your-website/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to show 5 top categories in Wordpress</title>
		<link>http://www.ghacks.net/2009/04/09/how-to-show-5-top-categories-in-wordpress/</link>
		<comments>http://www.ghacks.net/2009/04/09/how-to-show-5-top-categories-in-wordpress/#comments</comments>
		<pubDate>Thu, 09 Apr 2009 10:02:44 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[blog]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=11827</guid>
		<description><![CDATA[Wordpress is a great piece of software, and allows more than you&#8217;d think to be done with simple coding. I bet that a lot of people out there would look for a plugin to do this, but your top five categories can very easily be shown using a Wordpress template tag, just a half a [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.ghacks.net/wp-content/uploads/2009/04/wordpress.png" alt="wordpress" title="wordpress" width="128" height="128" class="alignleft size-full wp-image-11834" />Wordpress is a great piece of software, and allows more than you&#8217;d think to be done with simple coding. I bet that a lot of people out there would look for a plugin to do this, but your top five categories can very easily be shown using a Wordpress template tag, just a half a line of code.</p>
<p>The tag we need is called &#8220;wp_list_categories()&#8221; and by default it lists all your categories in alphabetical order. All we need to do is add some arguments to it to modify the default values and we&#8217;re done! We need to limit the number of items shown to five, we also want to show the post counts in the categories and we want to order the list by the post count, in descending order.</p>
<p>The &#8220;number&#8221; argument actually has no default value. The reason for this is that it limits the SQL query directly, so there is no need for it by default. We can add it though to impose a limit, so our first argument will be &#8220;number=5&#8243;. We also want to show the post counts, so we use &#8220;show_count=1&#8243; to enable this (show_count=0 is the default).</p>
<p><span id="more-11827"></span>We also want to order the list by the post count, so we use &#8220;orderby=count&#8221; to achieve this. By default lists are sorted ascending, meaning that the lowest post count would show up first. To make the list descending, we can use &#8220;order=DESC&#8221;.</p>
<p>I also use one last argument in there, which is &#8220;title_li=&#8221;. This sets the title of the list to be nothing, by default the list is presented with a title. I like to hard code my titles for a few reasons, but feel free to change this as you like. So here is the complete code I used, one simple line to do a seemingly hard task, enjoy</p>
<p>&lt;?php wp_list_categories(&#8217;number=5&amp;show_count=1&amp;orderby=count&amp;order=DESC&amp;title_li=&#8217;) ?&gt;</p>
<p><img class="alignleft size-full wp-image-10878" src="http://www.ghacks.net/wp-content/uploads/2009/03/scrip_twitter.gif" alt="Script" width="53" height="53" /><strong>If you&#8217;d like to read some similar articles, take a look at <a title="Web development blog" href="http://scriptastique.com">Scriptastique</a>, a blog all about web development and coding, with great tips on CSS, HTML, PHP, MySQL and Javascript and tutorials and screencasts coming soon! You can follow us on our <a title="Scriptastique RSS feed" href="http://feeds2.feedburner.com/scriptastique">RSS feed</a>, or <a title="Scriptastique on Twitter" href="http://twitter.com/scriptastique">Twitter</a> where we&#8217;re posting 3-4 short tips daily now!</strong></p>

	Tags: <a href="http://www.ghacks.net/tag/blog/" title="blog" rel="tag">blog</a>, <a href="http://www.ghacks.net/tag/categories/" title="categories" rel="tag">categories</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a>, <a href="http://www.ghacks.net/tag/wordpress/" title="wordpress" rel="tag">wordpress</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/04/08/wordpress-blogs-create-custom-tag-pages/" title="Wordpress Blogs: Create Custom Tag Pages (April 8, 2009)">Wordpress Blogs: Create Custom Tag Pages</a> (5)</li>
	<li><a href="http://www.ghacks.net/2008/08/05/zoundry-raven-portable-blog-editor/" title="Zoundry Raven portable Blog Editor (August 5, 2008)">Zoundry Raven portable Blog Editor</a> (6)</li>
	<li><a href="http://www.ghacks.net/2009/02/02/wordpress-your-attempt-to-edit-this-post-has-failed/" title="Wordpress: Your attempt to edit this post has failed (February 2, 2009)">Wordpress: Your attempt to edit this post has failed</a> (8)</li>
	<li><a href="http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/" title="Wordpress template tags you should know (March 29, 2009)">Wordpress template tags you should know</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/08/11/wordpress-remote-admin-password-reset-vulnerability/" title="Wordpress Remote Admin Password Reset Vulnerability (August 11, 2009)">Wordpress Remote Admin Password Reset Vulnerability</a> (13)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/04/09/how-to-show-5-top-categories-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Wordpress template tags you should know</title>
		<link>http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/</link>
		<comments>http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 14:41:55 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[template tags]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=11529</guid>
		<description><![CDATA[If you run a Wordpress blog, you will eventually want to make some modifications to your theme. Perhaps you want to show your tags, not just categories, perhaps you want the date in a different format, you might want to add the URL of the author to each post, there are a lot of things [...]]]></description>
			<content:encoded><![CDATA[<p>If you run a Wordpress blog, you will eventually want to make some modifications to your theme. Perhaps you want to show your tags, not just categories, perhaps you want the date in a different format, you might want to add the URL of the author to each post, there are a lot of things like that which can easily be done with a little knowledge of <a title="wordpress tags" href="http://codex.wordpress.org/Template_Tags" target="_blank">Wordpress template tags</a>, which are little PHP code snippets, but you don&#8217;t have to be a coder to use them.</p>
<p>The great thing about these tags is that they are very well documented &#8220;see link above&#8221;, and that they are extremely simple to use. You don&#8217;t need to know anything about PHP, so let me explain their basic use in common sense language. Wordpress uses a loop, elegantly called &#8220;the loop&#8221; in &#8220;Wordpressian&#8221;, which cycles through the posts you have.</p>
<p>If you show 10 posts on your main page, the loop cycles through the latest 10 posts. This means that one the first loop it will pull in the data of your latest post, on the second pass it will look at the second and so on. All the data is pulled, all you need to do is specify what you want to display out of that data, let&#8217;s take a look at how.</p>
<p><span id="more-11529"></span></p>
<p>First of all, you need to identify the start and the end of the loop. The loop starts with the following (there may be some variation) :</p>
<p>&lt;?php if(have_posts()) : ?&gt;<br />
&lt;?php while(have_posts()) : the_post(); ?&gt;</p>
<p>And ends with a &#8220;&lt;?php endwhile; ?&gt; &lt;?php endif; ?&gt;&#8221;. This end statement is usually followed by the page navigation links which let you &#8220;turn the page&#8221; to the next or previous posts. Anything inside the loop gets executed as many times as the number of posts which are shown.</p>
<p>If all you want is to show your title, you just need to put &#8220;&lt;?php the_title() ?&gt;&#8221;, and you will get the titles of your first 10 posts. If you also want to show the tags you can add &#8220;&lt;?php the_tags() ?&gt;&#8221;. There are many others you can add, and don&#8217;t forget, you also need some HTML and CSS to make them look good.</p>
<p>Here&#8217;s a list of the most basic ones and what they do, but you can see the full list and expanded usage by clicking on the link above. Remember that the following should be put in the form: &lt;?php function() ?&gt;</p>
<ul>
<li>the_title() &#8211; outputs the title of the</li>
<li>the_content() &#8211; displays the actual post body</li>
<li>the_category() &#8211; displays the categories the post is in</li>
<li>the_tags() &#8211; displays the tags for the post</li>
<li>the_author &#8211; outputs the post author&#8217;s name</li>
<li>the_author_url &#8211; outputs the link to the author&#8217;s page, used a lot in links with &#8220;the_author&#8221;</li>
<li>the_time() &#8211; outputs the time of the post, you need to add the format in the parenthesis</li>
<li>the_permalink &#8211; outputs the posts permalink, usually used in a link with &#8220;the_title&#8221;</li>
</ul>
<p>While I use many others now and again, there are loads of designs that only use these 8, you can do a lot, with these alone. As you can see, adding to and modifying a Wordpress template is not such a big deal, why not try it yourself?</p>
<p><img class="alignleft size-full wp-image-10878" src="http://www.ghacks.net/wp-content/uploads/2009/03/scrip_twitter.gif" alt="Script" width="53" height="53" /><strong>If you&#8217;d like to read some similar articles, take a look at <a title="Web development blog" href="http://scriptastique.com">Scriptastique</a>, a blog all about web development and coding, with great tips on CSS, HTML, PHP, MySQL and Javasctipt and tutorials and screencasts coming soon! You can follow us on our <a title="Scriptastique RSS feed" href="http://feeds2.feedburner.com/scriptastique">RSS feed</a>, or <a title="Scriptastique on Twitter" href="http://twitter.com/scriptastique">Twitter</a> and <a title="Scriptastique on Facebook" href="http://www.facebook.com/home.php?#/profile.php?id=1470106953&amp;ref=profile">Facebook</a>! </strong></p>

	Tags: <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/template-tags/" title="template tags" rel="tag">template tags</a>, <a href="http://www.ghacks.net/tag/wordpress/" title="wordpress" rel="tag">wordpress</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/" title="Web Development: How does PHP work? (January 8, 2009)">Web Development: How does PHP work?</a> (21)</li>
	<li><a href="http://www.ghacks.net/2009/04/09/how-to-show-5-top-categories-in-wordpress/" title="How to show 5 top categories in Wordpress (April 9, 2009)">How to show 5 top categories in Wordpress</a> (9)</li>
	<li><a href="http://www.ghacks.net/2009/08/26/do-more-with-your-wordpress-using-the-function-reference/" title="Do more with your Wordpress using the function reference (August 26, 2009)">Do more with your Wordpress using the function reference</a> (3)</li>
	<li><a href="http://www.ghacks.net/2008/08/05/zoundry-raven-portable-blog-editor/" title="Zoundry Raven portable Blog Editor (August 5, 2008)">Zoundry Raven portable Blog Editor</a> (6)</li>
	<li><a href="http://www.ghacks.net/2009/02/02/wordpress-your-attempt-to-edit-this-post-has-failed/" title="Wordpress: Your attempt to edit this post has failed (February 2, 2009)">Wordpress: Your attempt to edit this post has failed</a> (8)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Creating a simple multi-lingual website</title>
		<link>http://www.ghacks.net/2009/03/19/creating-a-simple-multi-lingual-website/</link>
		<comments>http://www.ghacks.net/2009/03/19/creating-a-simple-multi-lingual-website/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 16:54:33 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[languages]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php constants]]></category>
		<category><![CDATA[translation]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/2009/03/19/creating-a-simple-multi-lingual-website/</guid>
		<description><![CDATA[If you want to create a simple webpage for yourself, listing who you are, how you can be contected and what you do, you might want to add a few languages in there. You could use Google Translate, but that does not yield the best (and professional) results, so it would be best to translate [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to create a simple webpage for yourself, listing who you are, how you can be contected and what you do, you might want to add a few languages in there. You could use Google Translate, but that does not yield the best (and professional) results, so it would be best to translate the page yourself, or have someone do it for you.</p>
<p>Now, you could have different pages like &#8220;about_english.php&#8221; and &#8220;about_spanish.php&#8221;, but this would make updating a pain, and very inflexible, plus if you have 20 languages, it means 20 files per page. So how do we get around this? Let me introduce you guys, to PHP constants.</p>
<p>A constant is defined just like a variable, but as its name suggests, it is in fact constant. It can be echoed just like a variable, and is great for defining set pieces of text. Let me show you my method of using constants to easily keep multiple language versions of a webpage, without having to have multiple files for each page.</p>
<p><span id="more-11335"></span></p>
<p>First of all, let&#8217;s take a look at how to define constants. Constant names are uppercase strings, but must not begin with a number and should not start with a special character. For example, let&#8217;s define a constant:</p>
<p>define(&#8221;NAME&#8221;, &#8220;Daniel Pataki&#8221;);</p>
<p>In this exampe we have defined a constant called &#8220;NAME&#8221;, and gave it a value of &#8220;Daniel Pataki&#8221;. I gave the constant a describing name, so I know that this constant holds my name.</p>
<p>The way I create multiple languages is that I create 1 language file for each language. I name them according to the standard 2 letter convention. The English file is named &#8220;en.php&#8221;, the French would be &#8220;fr.php&#8221; and so on. I include the language file the user needs at the beginning of all my other files containing text, so they will automatically be defined. There are many way to approach this, but for now, let&#8217;s say that the page is always in English, unless a user clicks one of the language links. So at the beginning of the code I would write:</p>
<p>&lt;?php<br />
if (isset($_GET['lang']))<br />
include($_GET['lang'].&#8221;.php&#8221;);<br />
else<br />
include(&#8221;en.php&#8221;)<br />
?&gt;</p>
<p>This way the relevant file will be included only. Each file contains the list of definitions I need in the same structure. My name in the English version is &#8220;Daniel Pataki&#8221;, but in Hungarian we put our family names in the front, so in &#8220;hu.php&#8221; I would define it as:</p>
<p>define(&#8221;NAME&#8221;, &#8220;Pataki Dániel&#8221;);</p>
<p>In the page&#8217;s code, I can then simply type the following to display my name:</p>
<p>&lt;h2&gt;&lt;?php echo NAME ?&gt;&lt;/h2&gt;</p>
<p>This would show my name as a level 2 heading. If the user is viewing in English, the output would be &#8220;Daniel Pataki&#8221;, if the user is viewing in Hungarian it would display &#8220;Pataki Dániel&#8221;, since this time &#8220;hu.php&#8221; is included, and not &#8220;en.php&#8221;. Notice that when displaying contants you do no need to put any special characters before or after the constant name, just type the constant itself as you defined it.</p>
<p>You can use this method to create languages for larger sites too. The reason I especially like this is that it is quite easy to translate the site, you just need to send the file over to someone and he will be able to do it easily, without any training. If you have a larger site it might be a good idea to indicate where the constant will be used. You can do this by defining a constant name like &#8220;SIDEBAR_COMMENTS&#8217;, or &#8220;CONTACT_NAME&#8221;. This way you and your translators will have an easier time, especially if you also use PHP comments in the language file for further pointers.</p>
<p>&lt;em&gt;If you liked this article, perhaps you&#8217;d like to take a look at &lt;a href=&#8221;http://scriptastique.com&#8221;&gt;Scriptastique&lt;/a&gt;, which is a blog (and upcoming tutorial site) aimed at professional and aspiring coders. We just started, but there are daily posts and the tutorials (along with screencasts) are on the way!&lt;/em&gt;</p>

	Tags: <a href="http://www.ghacks.net/tag/languages/" title="languages" rel="tag">languages</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/php-constants/" title="php constants" rel="tag">php constants</a>, <a href="http://www.ghacks.net/tag/translation/" title="translation" rel="tag">translation</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/" title="Wordpress template tags you should know (March 29, 2009)">Wordpress template tags you should know</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/" title="Web Development: Standardizing variables to code faster (January 2, 2009)">Web Development: Standardizing variables to code faster</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/" title="Web Development: How does PHP work? (January 8, 2009)">Web Development: How does PHP work?</a> (21)</li>
	<li><a href="http://www.ghacks.net/2009/01/05/web-development-a-brief-history-of-time/" title="Web Development: A brief history of time() (January 5, 2009)">Web Development: A brief history of time()</a> (3)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/03/19/creating-a-simple-multi-lingual-website/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Web development roundup</title>
		<link>http://www.ghacks.net/2009/03/16/web-development-roundup/</link>
		<comments>http://www.ghacks.net/2009/03/16/web-development-roundup/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 17:31:05 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=11272</guid>
		<description><![CDATA[Last week was a bit less active in web development terms, but here&#8217;s a roundup of what you can find on Scriptastique if you haven&#8217;t been taking a look recently. 
We had a look at how a mysql query basically works, which will come in handy if you&#8217;re just learning about MySQL and PHP. The [...]]]></description>
			<content:encoded><![CDATA[<p>Last week was a bit less active in web development terms, but here&#8217;s a roundup of what you can find on <a href="http://scriptastique.com">Scriptastique</a> if you haven&#8217;t been taking a look recently. </p>
<p>We had a look at how a mysql query basically works, which will come in handy if you&#8217;re just learning about MySQL and PHP. The article focuses more on the technical side than how to create specific queries, but we&#8217;ll get there in the end too! Just after that we created some simple but effective excerpts from longer text automatically removing unwanted characters and spaces.</p>
<p>We also had a look at website mascots, why you should use them, how to use arithmetic operators in PHP and just today, why a coder should always be well slept (easier said than done). If you feel like taking a stroll down web development avanue visit the site, or follow us on <a href="http://twitter.com/scriptastique">Twitter</a> or our <a href="http://feeds2.feedburner.com/scriptastique">RSS feed</a>!<br />
<span id="more-11272"></span></p>

	Tags: <a href="http://www.ghacks.net/tag/mysql/" title="mysql" rel="tag">mysql</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/" title="Web Development: Standardizing variables to code faster (January 2, 2009)">Web Development: Standardizing variables to code faster</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
	<li><a href="http://www.ghacks.net/2008/12/28/portable-web-server/" title="Portable Web Server (December 28, 2008)">Portable Web Server</a> (8)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/03/16/web-development-roundup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Identifying each page using body tags and CSS</title>
		<link>http://www.ghacks.net/2009/03/11/identifying-each-page-using-body-tags-and-css/</link>
		<comments>http://www.ghacks.net/2009/03/11/identifying-each-page-using-body-tags-and-css/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 18:00:51 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[superglobal]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=11106</guid>
		<description><![CDATA[If you are building a large website, chances are you have a great little CSS stylesheet linked to every document which governs all the pages. But what do you do if you want just one of the pages to be completely different? You could of course go into your code and ad separate id-s and [...]]]></description>
			<content:encoded><![CDATA[<p>If you are building a large website, chances are you have a great little CSS stylesheet linked to every document which governs all the pages. But what do you do if you want just one of the pages to be completely different? You could of course go into your code and ad separate id-s and classes for specific elements, but I use a bit of an easier approach.</p>
<p>The basis of this is to use php code to determine the directory of the page you are viewing and also the page&#8217;s name itself. I will show you the code in a second, but let&#8217;s say you have a social network site underway and you keep you messaging system (outbox, inbox, new message, etc.) in a folder named &#8220;messaging&#8221;. In this case you can grab the name of the directory and the page and assign these as an id and a class to the body tag automatically, so it would look like this for the inbox: <em>&lt;body class=&#8221;messaging&#8221; id=&#8221;inbox&#8221;&gt;</em>.</p>
<p>This will make it very easy to add new rules in your stylesheet, since you can refer to whole documents in a directory using <strong>&#8220;body.messaging&#8221;</strong> and you can refer to specific pages using<strong> &#8220;body#inbox&#8221;</strong>. You can now use the same CSS file to change the look of only one page without the need to go in and add new classes and ids all the time. So how about the code to grab the directory and the page? Let&#8217;s take a look!</p>
<p><span id="more-11106"></span></p>
<p>First of all, let&#8217;s determine the page. For this we will use the <strong>&#8220;$_SERVER&#8221;</strong> superglobal variable which stores a lot of valuable information about the page you are viewing, the IP viewing the page and so on. Here&#8217;s the code as is, with the explanation coming up afterward.</p>
<pre>function page()
{
$page = substr(strrchr($_SERVER['PHP_SELF'],'/'),1,-4);
return $page;
}</pre>
<p>As you can see this is a function because I use it a lot throughout the site, not just for this one purpose. <strong>&#8220;$_SERVER['PHP_SELF']&#8220;</strong> will return the path to the file with the filename from your root directory, so it will look something either like this: <strong>&#8220;/directory/subdirectory/file.php&#8221;</strong> or if the file is in the root directory it will simply be <strong>&#8220;/file.php&#8221;</strong>. To get only the filename we want to chop off all the bits before the slash (and the slash itself), and also chop off the file extension.</p>
<p>As you can see the first thing I did was to chop off everything before the last slash using <strong>&#8220;strrchr()&#8221;</strong> which returns the part of the string after the last occurrence of the sub-string you specify. However, the last slash still remains, but this is not a problem, we can get rid of this, and the &#8220;.php&#8221; part in one go.</p>
<p>This is done by using <strong>&#8220;substr()&#8221;</strong>. The function took three arguments, the string we want to work with, and two integers. The first integer tells the function to start from character 1 (this means everything before that will be chopped off, in this case character 0, which is the slash) and then return everything up to the -4th character from the end. This means that four characters will be dropped from the end.</p>
<p>Now the variable <strong>&#8220;$page&#8221;</strong> contains only the readable part of the filename which would be &#8220;inbox&#8221; or &#8220;index&#8221;, without any slashes or the extension. You could also create this as a variable without using function. the reason I use a function is that I usually have some extra code in there which allows me to echo the function at once by default, but also to store it as a variable if needed.</p>
<p>Now, let&#8217;s take a look at determining the directory. We could take the same approach as before but chop off different bits, but PHP already has a function which will make our life easier, let&#8217;s take a look at the code:</p>
<pre>function thedir()
{
$dir = substr(strrchr(getcwd(), '/'),1);
return $dir;
}</pre>
<p>Using <strong>&#8220;getcwd()&#8221;</strong> we can get the current working directory. This will be in the form of <strong>&#8220;/directory/subdirectory&#8221;</strong>, so all we need to do is return everything after the last slash and chop the last slash off. We use the same technique as before, so now we also have our directory. Once done, all you need to do is modify your header, which should be in a PHP file to make the body tag look like this (calling the functions as the names for the class and id):</p>
<pre>&lt;body id="&lt;?php echo page() ?&gt; class="&lt;?php echo $thedir ?&gt;""&gt;</pre>
<p>There are some other ways to do this, some can be simpler or more complicated, this is more like the proving of a point, but it is totally usable and I use a modified version of it throughout my sites. This is not a whole lot of code extra and will make your site better structured and easier to modify.</p>
<p>Please be aware that<strong> &#8220;getcwd()&#8221;</strong> can give you some weird results if you changed your current working directory somewhere in your code. In this case you can use a modified version of the &#8216;page getting&#8217; code, or you can take a look at the <a href="http://hu.php.net/reserved.variables.server">server superglobal</a> section in the PHP manual for some more help.</p>
<p><img class="alignleft size-full wp-image-10878" src="http://www.ghacks.net/wp-content/uploads/2009/03/scrip_twitter.gif" alt="Script" width="53" height="53" /><strong>If you&#8217;d like to read some similar articles, take a look at <a title="Web development blog" href="http://scriptastique.com">Scriptastique</a>, a blog all about web development and coding, with great tips on CSS, HTML, PHP, MySQL and Javasctipt and tutorials and screencasts coming soon! You can follow us on our <a title="Scriptastique RSS feed" href="http://feeds2.feedburner.com/scriptastique">RSS feed</a>, or <a title="Scriptastique on Twitter" href="http://twitter.com/scriptastique">Twitter</a> and <a title="Scriptastique on Facebook" href="http://www.facebook.com/home.php?#/profile.php?id=1470106953&amp;ref=profile">Facebook</a>! </strong></p>

	Tags: <a href="http://www.ghacks.net/tag/css/" title="css" rel="tag">css</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/superglobal/" title="superglobal" rel="tag">superglobal</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/03/16/web-development-roundup/" title="Web development roundup (March 16, 2009)">Web development roundup</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/04/09/how-to-show-5-top-categories-in-wordpress/" title="How to show 5 top categories in Wordpress (April 9, 2009)">How to show 5 top categories in Wordpress</a> (9)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/03/11/identifying-each-page-using-body-tags-and-css/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Scriptastique web development roundup</title>
		<link>http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/</link>
		<comments>http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 12:55:01 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scriptastique]]></category>
		<category><![CDATA[web design]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=11035</guid>
		<description><![CDATA[As you all know, we started a web development section here on gHacks. After asking for your opinion and talking about it with Martin, we decided to keep writing 1-2 posts a week here, but move most of the material into a new site called Scriptastique. 
Right now we only have the blog, but tutorial [...]]]></description>
			<content:encoded><![CDATA[<p>As you all know, we started a web development section here on gHacks. After asking for your opinion and talking about it with Martin, we decided to keep writing 1-2 posts a week here, but move most of the material into a new site called <a title="Web development" href="http://scriptastique.com">Scriptastique</a>. </p>
<p>Right now we only have the blog, but tutorial sections and screencasts are on their way! To keep gHacks readers in the know, I will be doing a weekly short roundup of posts, if you like some of them, head on over to the site, take a look and participate in all the fun! So let&#8217;s jump to it, here&#8217;s what we covered on week 1.</p>
<ul>
<li>Checking MySQL queries for errors</li>
<li>Creating your first function in PHP</li>
<li>How the internet works &#8211; domains and hosting</li>
<li>Create cool icons in a flash for your website</li>
<li>Creating rounded corners using only CSS</li>
</ul>
<p>We have a few more up there, and you can follow us on Twitter and our RSS feed or join us on <a href="http://www.ghacks.net/2009/10/17/facebook-login/">Facebook</a>. If you have any questions or comments feel free to let me know!</p>
<p><span id="more-11035"></span></p>

	Tags: <a href="http://www.ghacks.net/tag/coding/" title="coding" rel="tag">coding</a>, <a href="http://www.ghacks.net/tag/html/" title="html" rel="tag">html</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/scriptastique/" title="scriptastique" rel="tag">scriptastique</a>, <a href="http://www.ghacks.net/tag/web-design/" title="web design" rel="tag">web design</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/03/04/how-echo-works-in-php/" title="How echo works in PHP (March 4, 2009)">How echo works in PHP</a> (2)</li>
	<li><a href="http://www.ghacks.net/2009/02/02/ghacks-web-development-pdf-article-compilation-january-09/" title="Ghacks Web Development PDF Article Compilation January 09 (February 2, 2009)">Ghacks Web Development PDF Article Compilation January 09</a> (6)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/07/11/a-standard-compliant-web-browser-and-editor-amaya/" title="A standard compliant web browser and editor: Amaya (July 11, 2009)">A standard compliant web browser and editor: Amaya</a> (2)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Passing variables using in the URL</title>
		<link>http://www.ghacks.net/2009/03/07/passing-variables-using-in-the-url/</link>
		<comments>http://www.ghacks.net/2009/03/07/passing-variables-using-in-the-url/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 22:19:07 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[dynamic content]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[url]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=10983</guid>
		<description><![CDATA[If you&#8217;ve seen some Wordpress blogs or online stores you&#8217;ve probably seen url-s in the form of http://somepage.com/product.php?id=4. These sites pass variables to scripts using the url. The script will scan the url for these and you can use them in a database query for example. This is the technology that allows Wordpress templates to [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve seen some Wordpress blogs or online stores you&#8217;ve probably seen url-s in the form of http://somepage.com/product.php?id=4. These sites pass variables to scripts using the url. The script will scan the url for these and you can use them in a database query for example. This is the technology that allows Wordpress templates to function, since you only need one page for all your posts.</p>
<p>Instead of creating a separate HTML page for each post we make, we enter our posts into a database. Each post is then assigned an id. We simply create one page, say posts.php and the code for that page contains a query, plus all the necessary HTML for displaying a post. This query will pull one specific post from the database and put the correct pieces where they should go in the template.  We can tell the script which one to pick by passing it a variable in the url. If the value of this variable is 135 for example, the post that will be pulled will be the one with this id.</p>
<p>You can see right away how valuable this is, you can build truly dynamic pages with this method. Your data is better organized in a database, and you can change the way you display it by simply modifying the HTML code, no need to recreate any content whatsoever. So how is this done on a code level? Let&#8217;s take a look!</p>
<p><span id="more-10983"></span></p>
<p>You need to use a PHP file obviously, and after the extension you need to write the names and the values of the variables you want to pass in the following format: http://url.com/page.php?variable=value&amp;variable=value. Notice that initially we use a question mark to separate the variable name passed from the extension, but after each subsequent variable passed we use an ampersand.</p>
<p>You can easily retrieve these variables in the code, referencing them with $_GET['variable']. For example, let&#8217;s say the url you use is the following: http://scriptastique.com/post.php?post_id=345. In this case inside the PHP file the value of $_GET['post_id'] is 345.</p>
<p>Using the &#8216;get&#8217; method you can pass strings, not just integers, so you could pass the name of the referring url, the name of a user, whatever you need. You should be aware though, that using the get method is unsafe if you want to send sensitive data. For example, you wouldn&#8217;t want to pass a user&#8217;s password from one page to another using the get method for many reasons, but mainly because it is displayed in the url bar.</p>
<p>For other things like telling a script which post you want to show, or which category you want the description for it&#8217;s fine, and a very comfortable way of organizing a huge site into just a few files, in fact, I think this is one of the best features of PHP!</p>
<p><em>If you liked this article, perhaps you&#8217;d like to take a look at <a href="http://scriptastique.com">Scriptastique</a>, which is a blog (and upcoming tutorial site) aimed at professional and aspiring coders. We just started, but there are daily posts and the tutorials (along with screencasts) are on the way!</em></p>

	Tags: <a href="http://www.ghacks.net/tag/dynamic-content/" title="dynamic content" rel="tag">dynamic content</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/url/" title="url" rel="tag">url</a>, <a href="http://www.ghacks.net/tag/variables/" title="variables" rel="tag">variables</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/" title="Wordpress template tags you should know (March 29, 2009)">Wordpress template tags you should know</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/" title="Web Development: Standardizing variables to code faster (January 2, 2009)">Web Development: Standardizing variables to code faster</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/" title="Web Development: How does PHP work? (January 8, 2009)">Web Development: How does PHP work?</a> (21)</li>
	<li><a href="http://www.ghacks.net/2009/01/05/web-development-a-brief-history-of-time/" title="Web Development: A brief history of time() (January 5, 2009)">Web Development: A brief history of time()</a> (3)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/03/07/passing-variables-using-in-the-url/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How echo works in PHP</title>
		<link>http://www.ghacks.net/2009/03/04/how-echo-works-in-php/</link>
		<comments>http://www.ghacks.net/2009/03/04/how-echo-works-in-php/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 09:22:52 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[echo]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=10874</guid>
		<description><![CDATA[The most basic command, and probably the first you&#8217;ll learn when taking a look at PHP is &#8220;echo&#8221;. The first example in many books and online tutorials is the following. Create a file, give it an extension of &#8220;.php&#8221;, upload it to your server, and edit it like so:
&#60;?php
echo &#8216;Hello World&#8217;;
?&#62;
I hate Hello World examples, [...]]]></description>
			<content:encoded><![CDATA[<p>The most basic command, and probably the first you&#8217;ll learn when taking a look at PHP is &#8220;echo&#8221;. The first example in many books and online tutorials is the following. Create a file, give it an extension of &#8220;.php&#8221;, upload it to your server, and edit it like so:</p>
<p>&lt;?php<br />
echo &#8216;Hello World&#8217;;<br />
?&gt;</p>
<p>I hate Hello World examples, but this shows what we are doing pretty well. Basically the echo command will write out that phrase &#8220;Hello World&#8221; (the quotes will not be shown, the single quotes above are part of the code), so if you open that file using <a href="http://www.ghacks.net/tag/firefox/">Firefox</a> for example you should simply see the phrase.</p>
<p>This seems straightforward, but to really understand what&#8217;s happening, and to be able to work with PHP efficiently we need to dig a bit deeper to see what really happens when we echo something.</p>
<p><span id="more-10874"></span>The most important thing you need to understand is that PHP is a server side language. This means that whatever code you write is never sent directly to the client (the viewer of your site for example). When someone opens a PHP file form the next the file is first processed by the server, and <strong>only the result</strong> is shown to the user. This is why you will never see PHP code if you view the source of a page.</p>
<p>You also need to know that once the server has processed the file it retruns pure browser readable code. I would say pure HTML, but obviously your PHP file can contain inline javascript, just like your HTML files. Now echoing something tells the server that whatever is echoed should be placed as is into the HTML file. This means that whenever you want to put HTML tags when you are echoing you can do so by writing them as you would in an HTML file itself, like this:</p>
<p>&lt;?php<br />
echo &#8216;&lt;strong&gt;Hello World&lt;/strong&gt;&#8217;;<br />
?&gt;</p>
<p>Once the server has returned its result, this is downloaded by the browser and processed like usual, so your &#8220;strong&#8221; tags wil be taken into account and will indeed bold text.</p>
<p>So what&#8217;s the point of sending the server that bit of code if all it does is just put it in like it was HTML? Well, the answer lies further down the road, but basically this is helpful because you can prevent/enable specific of section of code reaching the client, so the viewer only downloads what he/she needs, not the whole file. A simple example:</p>
<p>&lt;?php<br />
$random = rand(0, 99);</p>
<p>if ($random &gt; 50)<br />
echo &#8216;Number is above fifty&#8217;;<br />
else<br />
&amp;nbsp; &amp;nbsp; echo &#8216;Number is equal to or less than fifty&#8217;;<br />
?&gt;</p>
<p>Without really understanding what&#8217;d going on I can still explain. We create a variable, the value of it will be a randomly generated number between 0 and 99. If this number which we just generated is above 50 then we should echo that it is above fifty, in all other cases (it is below or equal to fifty), we should echo the other statement.</p>
<p>This is processed whenever someone loads (or reloads) a page, so the variable &#8220;$random&#8221; will always be different, generated &#8220;on the fly&#8221;. The script then checks the number, and only the relevant piece of code is returned, so if the number generated is 55 the only piece of code that you will see in the source will be:</p>
<p>The number is above fifty</p>
<p>Obviously this is a bit over-simplified, but in real life this is basically what happens. You can also use this to generate different pieces of code for different days of the week, and the change will be automatic, you only need to program once. You can also use it to create one file to display all your posts (like in Wordpress), so you don1t have to code a page for each post you write. PHP is awesome, start lovin&#8217; it!</p>
<p><img class="alignleft size-full wp-image-10878" src="http://www.ghacks.net/wp-content/uploads/2009/03/scrip_twitter.gif" alt="Script" width="54" height="54" /><em>If you would like to read more articles like this, take a look at <a title="Coding and web development blog" href="http://scriptastique.com" target="_blank">Scriptastique</a>, a new blog by the writer, Daniel Pataki. The site will contain different articles from the ones published here, and will eventually have complete tutorials for numerous programming languages.</em></p>

	Tags: <a href="http://www.ghacks.net/tag/coding/" title="coding" rel="tag">coding</a>, <a href="http://www.ghacks.net/tag/echo/" title="echo" rel="tag">echo</a>, <a href="http://www.ghacks.net/tag/html/" title="html" rel="tag">html</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/02/02/ghacks-web-development-pdf-article-compilation-january-09/" title="Ghacks Web Development PDF Article Compilation January 09 (February 2, 2009)">Ghacks Web Development PDF Article Compilation January 09</a> (6)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/01/31/web-development-html-playground/" title="Web Development: HTML Playground (January 31, 2009)">Web Development: HTML Playground</a> (7)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/03/04/how-echo-works-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP &#8211; what it does and what it doesn&#8217;t</title>
		<link>http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/</link>
		<comments>http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 19:28:22 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Tutorials Basic]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[LAMP]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[website development]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=10600</guid>
		<description><![CDATA[PHP is a Server side scripting language. Its primary competitors are ASP (Microsoft), JSP (Sun), CFM (Adobe), and Perl (often called cgi by hosting companies, although it is not the only cgi language).
PHP was originally created in 1995, so as a technology it is fairly mature. Version 5.x is the latest stable version and 6 [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is a Server side scripting language. Its primary competitors are ASP (Microsoft), JSP (Sun), CFM (Adobe), and Perl (often called cgi by hosting companies, although it is not the only cgi language).<br />
PHP was originally created in 1995, so as a technology it is fairly mature. Version 5.x is the latest stable version and 6 is under development. It is currently running almost 20 million websites including big names like <a href="http://www.ghacks.net/2009/10/17/facebook-login/">Facebook</a>.</p>
<p>The most common server architecture on which PHP is found is called LAMP (for Linux + Apache + MySQL + PHP). All of the elements of LAMP are open source, meaning that the source code of the application is freely available. This means that the cost of setting up a server running LAMP is reduced (No License Fees), so LAMP based web hosting tends to be the least expensive solution available.</p>
<p>The Internet is built on a client-server architecture. On the client side we have the user and the browser. One the server side we have the server and its script interpreter (In our case, Apache and PHP).<br />
Because PHP runs on the server side, we cannot use it for flashy client side effects, things like animations and auto-complete cannot be performed by php because php is only running on the server. For client side programming we could use javascript, Flash/Flex, Silverlight, or JavaFX.</p>
<p><span id="more-10600"></span>What we can do with PHP is access a database, connect to other websites/services for information, and build a page out of smaller pieces, which we then deliver to the client for rendering.</p>
<p>I think it is important to indicate at this time that there are four levels at which you can work with PHP.</p>
<ol>
<li>Scripting &#8211; this is where you take a small script and add it (integrate) into an existing page.</li>
<li>Coding &#8211; this is where you write scripts as needed to add basic functionality to your site.</li>
<li>Development &#8211; this is where you write an full application in PHP.</li>
<li>Architect &#8211; this is where you properly design an application that develop it into an application. Like development but puts a lot more thought into a good foundation.</li>
</ol>
<p>Depending on your actual needs, several of these layers could be overkill for your task. The following articles will mainly be focused on the first two levels &#8211; scripting, and coding. In Scripting and coding we have two primary tasks we accomplish. One makes your job as webmaster easier. The second adds new functionality to your site.</p>
<p><a href="http://www.jeremiahstover.com">Jeremiah Stover</a> is a Software Engineer and a Business IT Consultant at <a href="http://www.pragmatic-development.com">Pragmatic Development</a>. He has hands on experience and regularly provides practical advice in Business, Marketing, IT equipment and software. His Specialties include interpersonal communications, design skills, teaching and instruction. Right now he spends most of his time developing web applications in PHP and MySQL.</p>

	Tags: <a href="http://www.ghacks.net/tag/css/" title="css" rel="tag">css</a>, <a href="http://www.ghacks.net/tag/html/" title="html" rel="tag">html</a>, <a href="http://www.ghacks.net/tag/lamp/" title="LAMP" rel="tag">LAMP</a>, <a href="http://www.ghacks.net/tag/mysql/" title="mysql" rel="tag">mysql</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/web-dev/" title="web dev" rel="tag">web dev</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a>, <a href="http://www.ghacks.net/tag/website-development/" title="website development" rel="tag">website development</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/02/02/ghacks-web-development-pdf-article-compilation-january-09/" title="Ghacks Web Development PDF Article Compilation January 09 (February 2, 2009)">Ghacks Web Development PDF Article Compilation January 09</a> (6)</li>
	<li><a href="http://www.ghacks.net/2009/01/31/web-development-html-playground/" title="Web Development: HTML Playground (January 31, 2009)">Web Development: HTML Playground</a> (7)</li>
	<li><a href="http://www.ghacks.net/2009/03/16/web-development-roundup/" title="Web development roundup (March 16, 2009)">Web development roundup</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ghacks Web Development PDF Article Compilation January 09</title>
		<link>http://www.ghacks.net/2009/02/02/ghacks-web-development-pdf-article-compilation-january-09/</link>
		<comments>http://www.ghacks.net/2009/02/02/ghacks-web-development-pdf-article-compilation-january-09/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 09:26:56 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[Compilations]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[article compilation]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[ghacks]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[webmaster]]></category>
		<category><![CDATA[website development]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=10279</guid>
		<description><![CDATA[The following article contains all web development articles that have been published in January 09. The articles are provided in PDF format to make them readable on most operating systems and devices. We are providing article compilations to give you the chance to read the articles offline and keep them as reference without having to [...]]]></description>
			<content:encoded><![CDATA[<p>The following article contains all web development articles that have been published in January 09. The articles are provided in PDF format to make them readable on most operating systems and devices. We are providing article compilations to give you the chance to read the articles offline and keep them as reference without having to hop back at our site whenever you want to look something up.</p>
<p>The following web development articles have been published in January 2009 at Ghacks:</p>
<p><span id="more-10279"></span><a href="http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/">How does PHP work?</a><br />
<a href="http://www.ghacks.net/2009/01/31/web-development-html-playground/">HTML Playground</a><br />
<a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/">PHP &#8211; what role does it fill</a><br />
<a href="http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/">Standardizing variables to code faster</a><br />
<a href="http://www.ghacks.net/2009/01/05/web-development-a-brief-history-of-time/">Web Development: A brief history of time()</a></p>
<p>You can download the pdf document by clicking on the link below.</p>
<p><a href='http://www.ghacks.net/wp-content/uploads/2009/02/ghacks_web_january_09.pdf'>ghacks web development january 09</a></p>

	Tags: <a href="http://www.ghacks.net/tag/article-compilation/" title="article compilation" rel="tag">article compilation</a>, <a href="http://www.ghacks.net/tag/coding/" title="coding" rel="tag">coding</a>, <a href="http://www.ghacks.net/tag/ghacks/" title="ghacks" rel="tag">ghacks</a>, <a href="http://www.ghacks.net/tag/html/" title="html" rel="tag">html</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a>, <a href="http://www.ghacks.net/tag/webmaster/" title="webmaster" rel="tag">webmaster</a>, <a href="http://www.ghacks.net/tag/website-development/" title="website development" rel="tag">website development</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/03/04/how-echo-works-in-php/" title="How echo works in PHP (March 4, 2009)">How echo works in PHP</a> (2)</li>
	<li><a href="http://www.ghacks.net/2009/05/29/web-development-realtime-fonts-changer/" title="Web Development: Realtime Fonts Changer (May 29, 2009)">Web Development: Realtime Fonts Changer</a> (1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/02/02/ghacks-web-development-pdf-article-compilation-january-09/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Web Development: PHP &#8211; what role does it fill</title>
		<link>http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/</link>
		<comments>http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 09:03:18 +0000</pubDate>
		<dc:creator>Jeremiah</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web dev]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[website development]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=10259</guid>
		<description><![CDATA[Before we try to work with PHP we need understand the role it fills – what problem does it address. The World Wide Web is built on a client-server model.  A client computer requests a page which is supplied by a Web Server. The browser then renders the page for the user to view. [...]]]></description>
			<content:encoded><![CDATA[<p>Before we try to work with PHP we need understand the role it fills – what problem does it address. The World Wide Web is built on a client-server model.  A client computer requests a page which is supplied by a Web Server. The browser then renders the page for the user to view. The simplest type of pages contain static (unchanging) content. The server could serve plain text files, and the browser wouldn&#8217;t have any trouble rendering them. </p>
<p>HTML is a markup language that lets us describe attributes of the text and blocks on our pages. This works great for simple requests, making pages much more interesting than plain text. However it leaves us with a very simple structure. One page from One url (address) results in one rendered content (every time this url is requested, the output is the same).</p>
<p>To give us more options we have programming languages. Some like PHP run on the server side. They modify the content that will be displayed before it is sent to the client and on to the browser. Others like JavaScript run on the client side and allow changes to be made in the browser after the page has been rendered – usually for interactivity or for adding a feature not normally available in that browser.</p>
<p><span id="more-10259"></span>The very first thing you _must_ do before getting started with PHP is get a good grasp of HTML (and CSS). Many webmasters use a tool like Dreamweaver, Expression Web or KompoZer. To<br />
work with PHP it is important that you understand the underlying HTML code. You will be modifying this code so you need to be able to understand the HTML well enough to understand what you see.</p>
<p>If you like video training try Lynda.com or VTC.com. If you prefer reading a book try &#8220;Head First html with CSS &#038; Xhtml&#8221; or if you prefer free web instruction try <a href="http://w3schools.com">w3schools.com</a> and <a href="http://tizag.com">tizag.com</a>.</p>
<p>Now that you understand the markup language which is what is sent to the browser (HTML) you are ready to tackle the server side use of PHP.</p>
<p>Jeremiah Stover is a Software Developer at <a href="http://www.pragmatic-development.com/">Pragmatic Development</a>. He specializes in client communications. While PD does offer a full range of IT services and consulting, they are currently specializing in website development in PHP/MySQL.</p>

	Tags: <a href="http://www.ghacks.net/tag/css/" title="css" rel="tag">css</a>, <a href="http://www.ghacks.net/tag/html/" title="html" rel="tag">html</a>, <a href="http://www.ghacks.net/tag/mysql/" title="mysql" rel="tag">mysql</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/web-dev/" title="web dev" rel="tag">web dev</a>, <a href="http://www.ghacks.net/tag/web-development/" title="web development" rel="tag">web development</a>, <a href="http://www.ghacks.net/tag/website-development/" title="website development" rel="tag">website development</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/02/02/ghacks-web-development-pdf-article-compilation-january-09/" title="Ghacks Web Development PDF Article Compilation January 09 (February 2, 2009)">Ghacks Web Development PDF Article Compilation January 09</a> (6)</li>
	<li><a href="http://www.ghacks.net/2009/01/31/web-development-html-playground/" title="Web Development: HTML Playground (January 31, 2009)">Web Development: HTML Playground</a> (7)</li>
	<li><a href="http://www.ghacks.net/2009/03/16/web-development-roundup/" title="Web development roundup (March 16, 2009)">Web development roundup</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Web Development: How does PHP work?</title>
		<link>http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/</link>
		<comments>http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 19:56:42 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=9687</guid>
		<description><![CDATA[When someone starts learning web development they usually start with HTML and CSS, and many people get stuck there without ever experiencing the wonderful workd of server side scripting like PHP or ASP. I&#8217;ll be talking about PHP here, but the basic rules for ASP and others are the same though.
The most important thing to [...]]]></description>
			<content:encoded><![CDATA[<p>When someone starts learning web development they usually start with HTML and CSS, and many people get stuck there without ever experiencing the wonderful workd of server side scripting like PHP or ASP. I&#8217;ll be talking about PHP here, but the basic rules for ASP and others are the same though.</p>
<p>The most important thing to understand is the difference between HTML and PHP. In HTML you write your code, upload it, and the user&#8217;s will subsequently download that page along with <strong>all the code</strong>. The user&#8217;s browser interprets this code and shows the user the page as you intended it (hopefully). In other words HTML is sort of what you see is what you get, in the sense that all the code goes to the user and is interpreted by the browser.</p>
<p>With PHP it works a bit differently because you don&#8217;t actually download the code the author wrote. What happens is that if you want to download a php page the code in that file is first processed by the server, and you download the <strong>output of the code</strong>, as opposed to the whole code as is. This in turn will be HTML just as before, this is why you never see PHP code in the source of a webpage. So what happens in processing? Turn the page to find out!</p>
<p><span id="more-9687"></span>With PHP the goal is to use the processing powers of the server to build (usually) dynamic webpages. A very basic example is showing the correct greeting for the time of day on a webpage. In human terms you write a script with the directions to show &#8220;Good Morning&#8221; if it is before 10am but after 5am, &#8220;Good Afternoon&#8221; if it is after 10am but before 6pm and &#8220;Good Night&#8221; after 6pm, before 5am. Instead of receiving all the code for this and processing it in your browser, this all gets processed before you download it, and you only get the result of the process, the text &#8220;Good Night&#8221; for example if it is 9pm.</p>
<p>This is much quicker, since if you think of bigger sites, instead of having to download 300kb (or much more) of code, it is quickly processed on the server and you might get as little as 10kb or less. Obviously your PC could process the code quickly, but downloading and handling can take a while. In addition, the code may also have database queries which can not execute if processed on your PC, they have to be processed on the server which has the database.</p>
<p>If you would like a more real-life example, take a look at gHacks, which has almost 5,000 posts now. In HTML world we would have to have 5,000 posts which all have the whole site code, from header to footer with the article in between. PHP makes it possible to &#8220;compress&#8221; those 5,000 files into only 1!</p>
<p>When you view any gHacks post on a single post page you are actually viewing a file called single.php. This file also has some additional info in the url which will tell the script which post to show, so the file you are viewing would be single.php?p=234. This tells the script that the post with the ID of 234 needs to be shown. The script queries the database for the relevant post and pulls its details (like title and post body) from the database. So in the end all you are shown is one post. Wordpress has some other stuff built in to make nicer URL&#8217;s and so on, but under the hood this is what is happening.</p>
<p>Likewise for the front page we don&#8217;t always go and modify the code when posting something. Martin would be coding all day, removing the last post on the page and pasting the code of the new one. Instead, in the php file you are viewing the code gets the latest 10 posts and puts their data on the page.</p>
<p>There is a lot more to learn in PHP, but those are the basic mechanics, the ability to create pages based on certain criteria, as opposed to static content on each page.</p>

	Tags: <a href="http://www.ghacks.net/tag/html/" title="html" rel="tag">html</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/wordpress/" title="wordpress" rel="tag">wordpress</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/" title="Wordpress template tags you should know (March 29, 2009)">Wordpress template tags you should know</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/09/scriptastique-web-development-roundup/" title="Scriptastique web development roundup (March 9, 2009)">Scriptastique web development roundup</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/04/09/how-to-show-5-top-categories-in-wordpress/" title="How to show 5 top categories in Wordpress (April 9, 2009)">How to show 5 top categories in Wordpress</a> (9)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Web Development: A brief history of time()</title>
		<link>http://www.ghacks.net/2009/01/05/web-development-a-brief-history-of-time/</link>
		<comments>http://www.ghacks.net/2009/01/05/web-development-a-brief-history-of-time/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 10:28:50 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[fucntions]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[time]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=9579</guid>
		<description><![CDATA[Part of the beauty of PHP to me is the number of really useful variables that are built in. Some of these might seem very odd at first, but once you start creating pages you will run into some problems which you&#8217;ll find can be solved by a function which seemed totally useless when you [...]]]></description>
			<content:encoded><![CDATA[<p>Part of the beauty of PHP to me is the number of really useful variables that are built in. Some of these might seem very odd at first, but once you start creating pages you will run into some problems which you&#8217;ll find can be solved by a function which seemed totally useless when you first heard of it. One of these functions for me was <em>time()</em>.</p>
<p>Echoing the <em>time()</em> function will give you the amount of time passed since the Unix Epoch in seconds. Say what? Epoch means a point in time chosen as the start of a period or an era and thus the Unix Epoch is January 1 1970 00:00:00 GMT. So echoing the <em>time()</em> function will give us &#8220;1230978041&#8243; at the time I&#8217;m writing this, meaning that 1,230,978,041 seconds have passed since then. So why is this useful to us?</p>
<p>Mathematically it gives us a much easier way of keeping track of time. Sure, 2008, Jan 15th might seem all nice and organized to you, but to calculate the days passed from the 15th of Januaray to the 17th we&#8217;s have to strip the numbers of &#8220;th&#8221;, and in more complicated cases perform a bunch of other string changes. Using time you can essentially assign a number value to any given second, making it much easier to use, especially as a counter.</p>
<p><span id="more-9579"></span></p>
<p>The place I use it most is to log out users of a website automatically after an inactivity period. When a user signs in I create all the session variables for him/her, and I also create one which holds the time his session should expire. The beauty of this whole system is that I do not need to know the actual time, I can just assign a value to the session variable like this:</p>
<p><em>$_SESSION['user']['time'] = time() +3600</em></p>
<p>This means that the user can stay logged in for 3,600 seconds (in other words an hour) from this moment in time. This is a very convenient way of defining expiration time, since you can think in terms of how long you want it to be, as opposed to trying to calculate a specific date and time.</p>
<p>When a user refreshes a page, or moves on to a new one, a script will check the value of the session variable. If the current time is smaller than the session variable, the user can stay logged in and I also usually prolong the session by another 3,600 seconds. This gives it the true &#8220;inactivity&#8221; aspect, since the user is allowed to stay logged in for more than an hour, as long as he/she is using the system. You could however choose not to prolong the session, in this case the user would have to log in again after one hour no matter what. In some high security systems this might be the way to go, or if you want the user to spend exactly one hour on a specific puzzle, there are many uses for everything. Needless to say that if the current time is more than the session variable the user is signed out.</p>
<p>Another common use for <em>time()</em> is to serve as the basis for generating a random ID, or character set, in other words, it can serve as a seed. A quite efficient way of creating a very random string would be to use <em>time()</em>, divide it by a random number generated between 0 and 9,999, add some random characters to it, and encode the whole thing using the SHA1 algorithm for example. Code-wise this is not as difficult or as long as it may sound, and it is pretty random and strong, although I am no security specialist.</p>
<p>if you have any cool uses for the<em> time()</em> function let us know in the comments!</p>

	Tags: <a href="http://www.ghacks.net/tag/fucntions/" title="fucntions" rel="tag">fucntions</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/time/" title="time" rel="tag">time</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/03/29/wordpress-template-tags-you-should-know/" title="Wordpress template tags you should know (March 29, 2009)">Wordpress template tags you should know</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/" title="Web Development: Standardizing variables to code faster (January 2, 2009)">Web Development: Standardizing variables to code faster</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/01/08/web-development-how-does-php-work/" title="Web Development: How does PHP work? (January 8, 2009)">Web Development: How does PHP work?</a> (21)</li>
	<li><a href="http://www.ghacks.net/2009/03/16/web-development-roundup/" title="Web development roundup (March 16, 2009)">Web development roundup</a> (1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/01/05/web-development-a-brief-history-of-time/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Web Development: Standardizing variables to code faster</title>
		<link>http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/</link>
		<comments>http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 16:33:19 +0000</pubDate>
		<dc:creator>Daniel Pataki</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=9555</guid>
		<description><![CDATA[Welcome to a new exploratory post here on gHacks! I actually work as a web designer specializing in standalone PHP and MySQL based sites, and I&#8217;ve always wanted to write a bit about coding, but it doesn&#8217;t really fit my own blog and I just don&#8217;t have time to start a whole new blog for [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to a new exploratory post here on gHacks! I actually work as a web designer specializing in standalone PHP and MySQL based sites, and I&#8217;ve always wanted to write a bit about coding, but it doesn&#8217;t really fit my own blog and I just don&#8217;t have time to start a whole new blog for it. Since gHacks is a tech blog we thought we&#8217;d try it out here with Martin and see how it goes. if you like the idea of similar posts here on gHacks please let us know in the comments (and also if you don&#8217;t), we want to post stuff you guys are interested in, so feel free to boo it on out of here! So here goes nothing:</p>
<p>If you&#8217;ve been coding for a while you probably have some set ways in which you work. I recommend you also widen this method to naming variables, which when done consistently can be a huge help, especially when you are using some fancy MySQL along with your PHP code. If you are building a site with 15 MySQL tables it is helpful if you know all the column names because you always name them in the same way, but the same thing goes for simple variables, and even ids and classes for HTML elements. </p>
<p>A very common example can be variables which hold a user&#8217;s data. In my case I always use the variable &#8216;$u&#8217; for holding the username, and the variable &#8216;$p&#8217; for holding the password. If you are grabbing a lot of data, like first name, last name, email and so on you can make up your own standard set, I use &#8216;$fn&#8217;, &#8216;$ln&#8217; and &#8216;$e&#8217; respectively for the three. </p>
<p><span id="more-9555"></span>Since you usually use these variables in the same script the importance of naming them consistently may not seem like a huge time saver. However when you get into session variables it saves you a lot of time if you don&#8217;t always have to look at where you are defining them to find out the names of each. I pull user data using a mysql query when a user logs in and I immediately place the whole array in a session variable name &#8220;$_SESSION['user']&#8220;. The names of the columns represent the values of this array, so the username and email would respectively become &#8220;$_SESSION['user']['Username']&#8220;, &#8220;$_SESSION['user']['Email']&#8220;. This is the same in my case for every single website I build where applicable. </p>
<p>User data naming consistency is also very prominent in the MySQL tables themselves. As you can see above my columns are also named the same in each case, a user&#8217;s email is always &#8220;Email&#8221;, his last name is always &#8220;LastName&#8221;. I steer clear of abbreviations with MySQL tables so other coders can easily see what&#8217;s going on as well. Consistency doesn&#8217;t just apply to the actual names, you can also apply it to cases. As you can see all my column names are always capitalized, they are like wikiwords, but user session variables which don&#8217;t come from MySQL are not capitalized. For example, when a user logs in he is assigned a time, which is usually one hour. If he/she is inactive for more than this time (no refreshes), he/she is logged out. There is no need to store this in the database, and so I know that this is not in there the session variable here is &#8220;$_SESSION['user']['time']&#8220;. This means that if I come back to work on a site a year after completion I know exactly where variables come from. </p>
<p>Even if you don&#8217;t yet know any PHP, you&#8217;re just getting into HTML and CSS you can still use these good practices. When assigning ids and classes to elements try and work out a structure for yourself that you always use. I use empty div tags to clear floats a lot, so I have a separate class named &#8220;cl&#8221; for this purpose. Whenever I start out a new webpage I include this class by default in the stylesheet since I know I will most likely need it. </p>
<p>That&#8217;s about it for standardizing your coding work, most of it is just common sense really. Try and work out your own method which works best for you. It takes time and a lot of practice to get a system working well since there is so much to think of, but if you always keep this in mind somewhere while coding you&#8217;ll be a faster and better coder in no time at all!</p>

	Tags: <a href="http://www.ghacks.net/tag/mysql/" title="mysql" rel="tag">mysql</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
	<li><a href="http://www.ghacks.net/2009/03/16/web-development-roundup/" title="Web development roundup (March 16, 2009)">Web development roundup</a> (1)</li>
	<li><a href="http://www.ghacks.net/2008/12/28/portable-web-server/" title="Portable Web Server (December 28, 2008)">Portable Web Server</a> (8)</li>
	<li><a href="http://www.ghacks.net/2009/02/16/php-what-it-does-and-what-it-doesnt/" title="PHP &#8211; what it does and what it doesn&#8217;t (February 16, 2009)">PHP &#8211; what it does and what it doesn&#8217;t</a> (4)</li>
	<li><a href="http://www.ghacks.net/2009/09/17/local-apache-web-server-wampserver/" title="Local Apache Web Server Wampserver (September 17, 2009)">Local Apache Web Server Wampserver</a> (3)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Portable Web Server</title>
		<link>http://www.ghacks.net/2008/12/28/portable-web-server/</link>
		<comments>http://www.ghacks.net/2008/12/28/portable-web-server/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 15:28:53 +0000</pubDate>
		<dc:creator>Martin</dc:creator>
				<category><![CDATA[The Web]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[apache portable]]></category>
		<category><![CDATA[apache server]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pearl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[portable web server]]></category>
		<category><![CDATA[server2go]]></category>
		<category><![CDATA[sqlite]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://www.ghacks.net/?p=9407</guid>
		<description><![CDATA[Server2Go is a portable web server that can be run from any storage space in a Windows environment. It can be placed on USB devices, removable devices, CDs, DVDs or the hard drive of the computer. It requires no installation at all and can be run right from the location where it has been placed [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.server2go-web.de/download/download.html">Server2Go</a> is a portable web server that can be run from any storage space in a Windows environment. It can be placed on USB devices, removable devices, CDs, DVDs or the hard drive of the computer. It requires no installation at all and can be run right from the location where it has been placed it.</p>
<p>The web server can be downloaded in various configurations. The various configurations range from a bare-bone Apache web server to a web server supporting MySQL, SQLite, Pearl and PHP. The configuration only has an effect on the type of applications that can be run on the web server. Most users will probably need at least MySQL and PHP support to run their websites locally.</p>
<p>The web server can be started by double-clicking on the Server2Go.exe executable file in the root directory of the server. This will load the various web server modules and display a start page in the web browser. The pms_config.ini file can be used to change various settings of the web server including the default web browser, the port and whether the modules like MySQL or PHP should be started as well.</p>
<p><span id="more-9407"></span><img src="http://www.ghacks.net/wp-content/uploads/2008/12/server2go-500x253.jpg" alt="server2go" title="server2go" width="500" height="253" class="alignnone size-medium wp-image-9408" /></p>
<p>The actual files of a website are placed in the htdocs directory of the web server. Loading them can be as easy as pointing your browser to 127.0.0.1:4001 or some subdirectory of it depending on the type of site.</p>
<p>MySQL comes with phpMyAdmin which is accessible from the main interface of the web server. Server2Go offers an uncomplicated way to run a web server, it is especially helpful in environments where software installations are restricted.</p>

	Tags: <a href="http://www.ghacks.net/tag/apache/" title="apache" rel="tag">apache</a>, <a href="http://www.ghacks.net/tag/apache-portable/" title="apache portable" rel="tag">apache portable</a>, <a href="http://www.ghacks.net/tag/apache-server/" title="apache server" rel="tag">apache server</a>, <a href="http://www.ghacks.net/tag/mysql/" title="mysql" rel="tag">mysql</a>, <a href="http://www.ghacks.net/tag/pearl/" title="pearl" rel="tag">pearl</a>, <a href="http://www.ghacks.net/tag/php/" title="php" rel="tag">php</a>, <a href="http://www.ghacks.net/tag/portable-web-server/" title="portable web server" rel="tag">portable web server</a>, <a href="http://www.ghacks.net/tag/server2go/" title="server2go" rel="tag">server2go</a>, <a href="http://www.ghacks.net/tag/sqlite/" title="sqlite" rel="tag">sqlite</a>, <a href="http://www.ghacks.net/tag/web-server/" title="web server" rel="tag">web server</a><br />

	<h4>Related posts</h4>
	<ul class="st-related-posts">
	<li><a href="http://www.ghacks.net/2009/09/17/local-apache-web-server-wampserver/" title="Local Apache Web Server Wampserver (September 17, 2009)">Local Apache Web Server Wampserver</a> (3)</li>
	<li><a href="http://www.ghacks.net/2009/07/23/how-to-install-a-lamp-server/" title="How to: Install a LAMP server (July 23, 2009)">How to: Install a LAMP server</a> (6)</li>
	<li><a href="http://www.ghacks.net/2007/01/31/host-your-own-webserver/" title="Host your own webserver (January 31, 2007)">Host your own webserver</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/01/02/web-development-standardizing-variables-to-code-faster/" title="Web Development: Standardizing variables to code faster (January 2, 2009)">Web Development: Standardizing variables to code faster</a> (18)</li>
	<li><a href="http://www.ghacks.net/2009/02/01/web-development-php-what-role-does-it-fill/" title="Web Development: PHP &#8211; what role does it fill (February 1, 2009)">Web Development: PHP &#8211; what role does it fill</a> (1)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ghacks.net/2008/12/28/portable-web-server/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
