<?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>Vincent Reniers &#187; PHP</title>
	<atom:link href="http://blog.vincentr.be/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.vincentr.be</link>
	<description>From PHP Guru to Designer!</description>
	<lastBuildDate>Fri, 02 Jul 2010 17:59:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Nexis version 0.7</title>
		<link>http://blog.vincentr.be/2010/01/15/nexis-version-0-7/</link>
		<comments>http://blog.vincentr.be/2010/01/15/nexis-version-0-7/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 22:52:33 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Nexis]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.vincentr.be/?p=260</guid>
		<description><![CDATA[For the past few months, I&#8217;ve continued my work at my content management system. Since the start of the project in April 2009 the software has achieved quite some structure and features. All this with one goal in mind, to make things easier while developing websites. At this point, there only needs some minor functions [...]]]></description>
			<content:encoded><![CDATA[<p>For the past few months, I&#8217;ve continued my work at my content management system. Since the start of the project in April 2009 the software has achieved quite some structure and features. All this with one goal in mind, to make things easier while developing websites. At this point, there only needs some minor functions to be added to the system such as ACL (Access Control List) and more advanced language support. When it comes to performance tweaks I&#8217;ve tried to minimize the loops and queries, and with only about 10 000 to 12 000 lines of PHP I&#8217;d say this CMS is quite lightweight. Also to maintain optimal performance for more high-traffic website I&#8217;m still thinking about improving the cache. Now to decide wether this is the CMS you want to use for your site you would of course want to have a look at it&#8217;s features. I&#8217;ll try to give a good overview but I might add some new features later on because I could have forgotten about some.</p>
<h2>Structure</h2>
<p><img class="alignright" title="CMS Structure" src="http://vincentr.be/temp/images/structure-cms.gif" alt="" />The aspect is the structure of the CMS, it&#8217;s not Module-View-Controller based but it&#8217;s something different. There are 8 different directories, but you will only use a few of them most of the time: <strong>admin</strong>, <strong>lang</strong>, <strong>cache</strong>, <strong>images</strong>, <strong>css</strong>, <strong>templates</strong>, <strong>modules </strong>and <strong>system</strong>. The first directory contains the <strong>admin </strong>area, it is expandable but you can do this within your module so there isn&#8217;t much need to go in there. Then we have the <strong>lang </strong>and <strong>cache</strong> directories. These are maintained by the system and store system files. The <strong>images </strong>and <strong>css </strong>directories are just shared directories to be used amongst different templates e.g. error css. I might move that to one single html folder. The <strong>system </strong>directory contains functions, classes, configuration, imports, the router and database class. Only some of these files are imported by default because they are necessary to operate succesfully. Setting up your template is very easy. It doesn&#8217;t require a lot of changes, you just place some {TAGS} such as {MODULE} and {TITLE} which are automaticly filled in.</p>
<p>The module tag is controlled by the <strong>modules</strong>, these form the core of your application. They load the HTML files necessary to generate the content for the pages. The PHP and HTML is seperated from eachother by my own template engine. An example of a module could be <strong>news</strong>. This module will have an <strong>html</strong>, maybe <strong>xml </strong>(for ajax and rss feeds) directories. And a<strong> control.php file</strong>. I will go into this more deeply later on since there are also <strong>two different types</strong> of modules: background processes and display modules. Only one display module can be called at a time and the various background processes may run but these are often very simple such as a log to keep record of users. Now what a display module does is, when an action is called the php will process it. It will import the HTML file and put it on the {MODULE} tag and the html file may also contain its own user-defined tags which may be used to put php variables into or to place another html file. PHP can only be used in the html when it is written with a .phtml extension. The template engine will parse this file when it recognises this extension. So this makes a very clear distinction between PHP and HTML while giving the programmer the freedom of still beeing able to use PHP in the HTML if needed. There is no need to learn a custom template language.</p>
<h2>Features</h2>
<p>Now that you have a basic overview of the structure a good overview of features may be handy.</p>
<ul>
<li>Templates: seperate PHP from HTML</li>
<li>Support for multiple languages</li>
<li>Router for when you have mod_rewrite enabled, but this is not necessary</li>
<li>Advanced Caching</li>
<li>URL and Parameter validation on top-level.</li>
<li>Custom Error Handling</li>
<li>Database class for MySQL</li>
<li>Security for MySQL Injections</li>
<li>Admin area</li>
<li>User management</li>
<li>Access Control List</li>
<li>RSS Feed Generator</li>
<li>Support for AJAX Requests</li>
<li>Custom Template Engine</li>
<li>Extensions for Admin Area</li>
<li>Multiple templates (public and private)</li>
</ul>
<p>I&#8217;m sure I have forgotten about some functions, but these are the main functions that the system offers you =). Now wether I will make it openSource is still not sure.</p>
<h2>Example of a News Module</h2>
<p>Ok suppose we would like to create a module that serves news articles. We will create a directory &#8216;<strong>news</strong>&#8216; in modules. This module will contain a html folder with the <strong>HTML </strong>for the Article page and the HTML for each article.  So we create &#8216;<strong>news.html&#8217;</strong> and &#8216;<strong>article.html</strong>&#8216;. Now in news module we will also create a &#8216;<strong>display.php</strong>&#8216; file that will handle the actions. So basically what we have got now should look like:</p>
<p><img class="alignleft" title="News Module" src="http://vincentr.be/temp/images/module-news.gif" alt="News Module" />First of all we will have to tell the system to allow the request. So we open up the <strong>router </strong>and add this line.</p>
<p>This will tell the Router to allow News and to only accept parameters from article with a numeric value. You can specify extra options for more advanced url and parameter validation but we won&#8217;t go into that right now.</p>
<pre class="brush: php;">Router::setURL('/News/article/*');  </pre>
<p>Now we will supply some <strong>HTML </strong>to work with. An example of what &#8216;<strong>news.html</strong>&#8216; could look like is:</p>
<pre class="brush: xml;">&lt;h1&gt;News Page&lt;/h1&gt;

&lt;div id=&quot;articles&quot;&gt;{ARTICLES}&lt;/div&gt;</pre>
<p>Second we will create the HTML for the &#8216;<strong>article.html</strong>&#8216;.</p>
<pre class="brush: xml;">&lt;div class=&quot;article-preview&quot;&gt;
&lt;h2&gt;{TITLE}&lt;/h2&gt;

&lt;p&gt;{CONTENT}&lt;/p&gt;

&lt;a href=&quot;/news/article/{ID}&quot;&gt;Read More&lt;/a&gt;
&lt;/div&gt;</pre>
<p>Ok enough HTML written! Time to make this code work =). We will now go into the &#8216;<strong>display.php</strong>&#8216;:</p>
<pre class="brush: php;">$db-&gt;setQuery('SELECT `title`, `content`, `id` FROM `@__news` LIMIT 5');
$db-&gt;fetchList('Articles');

$tpl-&gt;loadHTML('news', 'Module');

foreach($Articles as $Article){
$tpl-&gt;loadHTML($html = 'article', $tag = 'Articles', true);
$tpl-&gt;Replace($Article);
}

$tpl-&gt;Delete('Articles');</pre>
<p>Only a few lines to make the entire news article work! Now let me explain this line by line because it may seem complicated at first sight. First we load the articles from the database. The <strong>@__</strong> is needed if you wish to make use of a table prefix. The results are loaded into the variable $Articles. Then we load in the HTML file and place it where the <strong>{MODULE} </strong>tag is located. Now this makes the tags in &#8216;<strong>news.html</strong>&#8216; available for use to the template engine. And then it will go through each article one by one and while we do this we will load in &#8216;<strong>article.html</strong>&#8216; each time and replace the tags inside them. And finally we will have to delete the remaining<strong> {ARTICLES}</strong> tag because we have specified a third parameter true in the loadHTML function which puts the <strong>{ARTICLES}</strong> tag back in place for use. Making it available for the second article and so on.</p>
<p>The replace function may be unclear right now, but what it does is. It sees that $Article is an array and for each key it tries to find an according tag and then it puts the values of the key on the location of the tag.<br />
Another method to do this would have been:</p>
<pre class="brush: php;">$tpl-&gt;Replace( array( 'title' =&gt; $Article['title'], 'content' =&gt; $Article['content'] ) ); </pre>
<p>But the example is just to show what kind of magic into some functions =). I hope you have enjoyed reading through this quick introduction. I hope it may provide you with some insight it the possibilities of using a cms. The reason why I think this CMS might be interesting is because it isn&#8217;t really based on one model out there, it is more a unique combination of what I thought to be the best solution I encountered each time while programming this system.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vincentr.be/2010/01/15/nexis-version-0-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internationalization in PHP</title>
		<link>http://blog.vincentr.be/2009/09/23/internationalization-in-php/</link>
		<comments>http://blog.vincentr.be/2009/09/23/internationalization-in-php/#comments</comments>
		<pubDate>Wed, 23 Sep 2009 18:16:09 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Internationalization]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[Nexus]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://vincentr.be/?p=242</guid>
		<description><![CDATA[Why have such a function?
While working at my CMS I was thinking on what would be the best way to manage the various languages and still make it easy to write the apps. After some thinking and taking the advice of a collegue into consideration I came to the conclusion that it would be best [...]]]></description>
			<content:encoded><![CDATA[<h3>Why have such a function?</h3>
<p>While working at my CMS I was thinking on what would be the best way to manage the various languages and still make it easy to write the apps. After some thinking and taking the advice of a collegue into consideration I came to the conclusion that it would be best to let all strings go through a function. The<strong> internationalization function __(&#8221;);</strong> why this function? Because it&#8217;s pretty much becoming a standard in other CMS. And I don&#8217;t want to make it hard for other devs if they need to understand my script.</p>
<h3>Now what exactly will this function do?</h3>
<p>First of all we want the string that we enter via this function to be translated into other languages. Now so we first need to know some information and ask yourself a few questions before programming. Like what languages has the user set? Are these languages active? Where do we find the translation? What if the translation is incorrect, how can the user change them?</p>
<p>So we could just make the translations hardcoded, but that wouldn&#8217;t be quite usable for a normal administrator to change these translations. Thats why we will also put them into the a DB Table. And of course this table will just be a reference for the backend since we do not want to go fetch a translation from the database all the time. Thats why you should store it in a file, this way it will be a lot faster. Ok yes you can cache it, but still if the cache is turned off retrieving them from files is a lot faster than running multiple queries. Now how to save them in files could be done in various ways. They could be stored in an .ini or .txt file and a line can be added each time there is a new translation. But storing them in a .php file would be a lot faster since the .ini, .txt files would have to be parsed each time. While when you would put the translations in an array the data is instantly available for use.</p>
<p>Now if there is a better way to store them in a PHP file then please let me know. But we&#8217;re just going to with this method. What the array could look like is this:</p>
<pre class="brush: php;">
array(
'english' =&gt; array(
'hello' =&gt; 'hello',
'how are you?' =&gt; 'how are you?',
),
'french' =&gt; array(
'hello' =&gt; 'bonjour',
'how are you?' =&gt; 'comment ça va?',
),
);</pre>
<p>Now when adding a new translation to the PHP file via fwrite it would be hard to put it on X amount of locations ( X = languages ) and than write it back again. Now that would be possible but it&#8217;s probably going to coss more load. Now a better (but temporary) way to do it I think could be by simply adding $lang[$language][$text] = $ translation; at the bottom. And then you could create a cronjob that will sort out these language files properly at the end of every day or make a script in the admin area for an administrator to do it. Now adding them directly to the array by finding the correct location could also work well.</p>
<p>Now how would you let the function create the translations for the other languages than the one you wrote it in? One way would be just duplicate the text and wait for an admin to change the values with the correct translations in the DB Table and then let it go to the file again. But a smart way would be to let it go through a Translator API and the generated translation would be ok 90% of the time.</p>
<h3>What if the function already found a translation?</h3>
<p>In this case you can just select the array of the language you&#8217;re currently working and than see if the string has been translated and go fetch it. Otherwise the function would have to do the steps described above.<br />
Anyways, these were my thoughts on how to create a good internationalization function. Now there could definitely be some easier ways to create it, and if you found one please let me know! I hope you learnt a bit on how to create it and I&#8217;m going to try and put this idea into code very soon =).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vincentr.be/2009/09/23/internationalization-in-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Templates</title>
		<link>http://blog.vincentr.be/2009/06/10/templates/</link>
		<comments>http://blog.vincentr.be/2009/06/10/templates/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 09:08:12 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[Template]]></category>

		<guid isPermaLink="false">http://vincentr.be/?p=136</guid>
		<description><![CDATA[It&#8217;s been a while since my last post but I can assure you that I&#8217;ve been quiet busy lately  . Right now I&#8217;m in the middle of my exams so I&#8217;ve been studying a lot and had no time for my PC etc. I&#8217;ve also been working on a lot on some designs and [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since my last post but I can assure you that I&#8217;ve been quiet busy lately <img src='http://blog.vincentr.be/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> . Right now I&#8217;m in the middle of my exams so I&#8217;ve been studying a lot and had no time for my PC etc. I&#8217;ve also been working on a lot on some designs and made an overview of my activities this year when it comes to Webdesign &amp; Development. I have made several designs and coded these layouts. But none of them have been implented in a CMS yet or just partially. Thats probably going to be my main concern for the moment. After that I might sell the other layouts (HTML &amp; CSS) or make them available for download.</p>
<p>I&#8217;m currently also spending some time on getting to know how frameworks work and what the best way is to build a custom CMS. Thats why I&#8217;ve ordered the book <strong>PHP5: CMS and Framework Development</strong> by <strong>Martin Brampton</strong>. So far it seems really interesting and has taught me a lot. This book also informs you about the way Mambo, Joomla and Aliro works because the author has developed many applications for these CMS and Framework. I might write a review about it soon but I still have a lot of pages to read and my time is limited at the moment. But I will most likely release some PHP application soon, maybe a shoutbox or tutorial so stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vincentr.be/2009/06/10/templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Tutorial : Log Visitors</title>
		<link>http://blog.vincentr.be/2009/04/19/php-tutorial-log-visitors/</link>
		<comments>http://blog.vincentr.be/2009/04/19/php-tutorial-log-visitors/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 19:48:08 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Visitors]]></category>

		<guid isPermaLink="false">http://vincentr.be/?p=101</guid>
		<description><![CDATA[Today we&#8217;re going to make a simple script that logs all of your visitors and puts it into a database. I will comment every step so you will understand how it works. For newbies who don&#8217;t understand PHP yet check out the first tutorial.
&#60;?php

$mysql_connect = mysql_connect('host', 'user', 'password') or die(&#34;We could not connect to the [...]]]></description>
			<content:encoded><![CDATA[<p>Today we&#8217;re going to make a simple script that logs all of your visitors and puts it into a database. I will comment every step so you will understand how it works. For newbies who don&#8217;t understand PHP yet check out the first tutorial.</p>
<pre class="brush: php;">&lt;?php

$mysql_connect = mysql_connect('host', 'user', 'password') or die(&quot;We could not connect to the MySQL server.&quot;);

// This is simple a connection to the database.
// I'll provide some details on how to construct the table inside the DB later.

$mysql_database = mysql_select('database') or die(&quot;We could not select the database.&quot;);
// Just pick a database where u made your 'visitor' table
// Note: or die(mysql_error()); Is very handy in most cases. It returns a very specific error.
// So now we have the database connection

$user = array();
$user['ip'] = $_SERVER['REMOTE_ADDR'];
$user['browser'] = $_SERVER['HTTP_USER_AGENT'];
$user['page'] = $_SERVER['PHP_SELF'];

// We now create an array and we fill in keys that contain values.
// These values are generated by PHP when a user runs your script (opens a page)
// These values then get put in the $_SERVER array and you can simply fetch them from there.

$insert = mysql_query(&quot;INSERT INTO `visitors` (`ip`,`browser`,`page`)VALUES($user['ip'], $user['browser'], $user['page']) &quot;) or die(mysql_error());
// This query inserts all the information we just gathered into our table.

?&gt;</pre>
<p>Now some info on how to create this table<br />
The table name : visitors<br />
Fields: 4<br />
First field is the : visitor_id  it is the Primary field and it auto increments and an Integer<br />
This means that it simply starts from 0 and always goes up , its a unique id for each field<br />
It helps a lot when you need to select one of these to set an ip to banned for example if you have such a column</p>
<p>Second field : visitor_ip   VARCHAR 255 or something<br />
Third field : browser  VARCHAR 355<br />
Fourth field : page   VARCHAR 35</p>
<p>You can easily set up tables and databases using <a href="http://www.phpmyadmin.net" target="_blank">PHPMyAdmin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vincentr.be/2009/04/19/php-tutorial-log-visitors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My CMS</title>
		<link>http://blog.vincentr.be/2009/04/19/my-cms/</link>
		<comments>http://blog.vincentr.be/2009/04/19/my-cms/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 17:31:26 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Portfolio]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Preview]]></category>

		<guid isPermaLink="false">http://vincentr.be/?p=94</guid>
		<description><![CDATA[Here is a quick picture of the CMS i am currently developping. You can see the default layout and a part of the template code wich is not yet finished. I still need to implent a way to import modules and widgets. The template class can get quiet complicated. I&#8217;m having this idea on how [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick picture of the CMS i am currently developping. You can see the default layout and a part of the template code wich is not yet finished. I still need to implent a way to import modules and widgets. The template class can get quiet complicated. I&#8217;m having this idea on how to load in the modules by assign a type to modules. First type is the passive one that is always loaded in and runs in on the back. The second is the type that is permanent and remains like on the sidebar. And the third one comes occasionally. Like a page or a box on the homepage. I&#8217;m not sure how this will operate. So i&#8217;m figuring the how-to part out first before getting to the coding part because if I don&#8217;t think this through it could get fucked up in the mid hehe. <img src='http://blog.vincentr.be/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Anyways tell me what you think about the default layout so far wich i&#8217;m going to use to construct the system on.</p>
<p style="text-align: center;"><a style="border:0px;" href="http://www.vincentr.be/temp/images/nexuscms.jpg"><img class="aligncenter" style="border: 2px solid #cccccc; margin-top: 10px; margin-bottom: 10px; width: 419px; height: 329px;" src="http://www.vincentr.be/temp/images/nexuscms.jpg" border="0" alt="Nexus CMS" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vincentr.be/2009/04/19/my-cms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Current Plans : New CMS</title>
		<link>http://blog.vincentr.be/2009/03/16/current-plans-new-cms/</link>
		<comments>http://blog.vincentr.be/2009/03/16/current-plans-new-cms/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 21:56:44 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://vincentr.be/2009/03/16/current-plans-new-cms/</guid>
		<description><![CDATA[At the moment I&#8217;m planning on making a new cms. So I&#8217;m looking at other applications and how their template engines work. The way they process errors, load modules and error handling etc. So far I&#8217;ve already managed to create a smooth looking template. It&#8217;s not finished so far, I will put it online as [...]]]></description>
			<content:encoded><![CDATA[<p>At the moment I&#8217;m planning on making a new cms. So I&#8217;m looking at other applications and how their template engines work. The way they process errors, load modules and error handling etc. So far I&#8217;ve already managed to create a smooth looking template. It&#8217;s not finished so far, I will put it online as soon as I&#8217;ve got it sliced etc. =).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vincentr.be/2009/03/16/current-plans-new-cms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP : Basics Explained</title>
		<link>http://blog.vincentr.be/2009/03/09/php-basics-explained/</link>
		<comments>http://blog.vincentr.be/2009/03/09/php-basics-explained/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 23:03:57 +0000</pubDate>
		<dc:creator>Vincent</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://vincentr.be/?p=51</guid>
		<description><![CDATA[1.Introduction
What is PHP? PHP is a server-side programming language. This means it processes a certain script to create a dynamic output in HTML. In most cases PHP is used together with some sort of Database such as MySQL. For example when a user clicks on the news page. The News.php script can ask the 10 [...]]]></description>
			<content:encoded><![CDATA[<p><strong>1.Introduction</strong><br />
What is PHP? PHP is a server-side programming language. This means it processes a certain script to create a dynamic output in HTML. In most cases PHP is used together with some sort of Database such as MySQL. For example when a user clicks on the news page. The News.php script can ask the 10 latest news articles from the MySQL database. And while it is requesting this information it can sort it out in HTML tables with a heading, comment button etc. When you&#8217;re just using HTML you can&#8217;t do this and your information will always be static. Now let us take a quick view at how a PHP script may be.</p>
<pre class="brush: php;">&lt;?php
echo(&quot;Hello Visitor&quot;);
?&gt;</pre>
<p>This will just output the string : Hello Visitor. As you can see the PHP script starts with &lt;?php and ends with ?&gt;. This tells the server when the PHP module will have to start processing the script and when the normal static HTML begins ( after the ?&gt;). Echo is the function. Functions can handle information the way you want them to deal with it. But we&#8217;ll come to that later. As you can see we tell the script that we&#8217;re processing a string by placing it between the &#8221; &#8221; quotes. And each function ends with a ; character. Let us continue with variables.</p>
<p><strong>2.Variables</strong></p>
<pre class="brush: php;">&lt;?php
$variablename  = &quot;content&quot;;
echo $variablename;
?&gt;</pre>
<p>This script will output : content . Variables are used to store information. Just temporary of course. After the script is done at the very very end. When the client is looking at the page with all the processed information. At this part the PHP script will automaticly remove these variables. This is an automatic process wich is called the &#8216;Garbage-collector&#8217;. But you can delete variables yourself if you like. You can do it this way.</p>
<pre class="brush: php;">&lt;?php
unset($variable);
?&gt;</pre>
<p><strong>3.Cookies</strong><br />
This is mostly advised when the variable holds a large amount of data. So you can unset it when you no longer need it. But when using normal scripts you don&#8217;t need to worry about it. Ok so how can you store information permantently? Through databases, with sessions or with cookies! Yes cookies =D. Cookies are stored in your browser, but of course the visitor needs to allow the cookies to be stored in his settings. Thats why you can&#8217;t login on sites when you don&#8217;t store cookies. For example when you login on some site. And your pass and username are correct the script normally creates a cookie with the name &#8216;username&#8217; and as value your name. And a cookie &#8216;password&#8217; and your password. And each time you go to a page the script checks if you have a cookie username so it recognises you as logged in. You can set cookies like this.</p>
<pre class="brush: php;">&lt;?php
setcookie(&quot;username&quot;, &quot;vincent&quot;); // for example
?&gt;</pre>
<p><strong>4.IF and ELSE statements</strong><br />
This is how you set a cookie. The text after the // is seen as a comment and the PHP script simply ignores this. Now you know what functions can do. PHP has a lot of functions preprogrammed wich you can find on <a title="PHP Documentation" href="http://www.php.net" target="_blank">www.php.net</a> As for the basics of PHP i&#8217;m going to explain you another aspect. After this you will understand the very basics and you will be set to learn a lot more in the documentation or with other tutorials.<br />
The IF and ELSE statements. These are so handy. Like suppose you want to see if a user is logged in.</p>
<pre class="brush: php;">&lt;?php
$user = $_COOKIE['username'];
if($user){
echo(&quot;Welcome $user&quot;);
}
else{
echo(&quot;Welcome Guest&quot;);
}
?&gt;</pre>
<p>The user variables gets the information from the cookie &#8216;username&#8217;. If it exists and if there is information in the cookie. It will welcome the user and display its username. Otherwise it will welcome the guest.<br />
The actions that will occur when the statement is true are always located between the { } brackets.</p>
<p>So that was my tutorial about the basics of PHP explained. I hope you have learnt a lot. And if you have any more questions don&#8217;t hesitate to comment below and ask your question =).</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.vincentr.be/2009/03/09/php-basics-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
