<?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>PHP Simple Tutorials &#187; Basic</title>
	<atom:link href="http://php.elegosproject.org/category/php/php-tutorials-basic/feed/" rel="self" type="application/rss+xml" />
	<link>http://php.elegosproject.org</link>
	<description>Free and user-friendly PHP tutorials</description>
	<lastBuildDate>Sun, 19 Jul 2009 13:12:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Accented letters and umlaut in PHP/HTML</title>
		<link>http://php.elegosproject.org/2009/07/19/accented-letters-and-umlaut-in-phphtml/</link>
		<comments>http://php.elegosproject.org/2009/07/19/accented-letters-and-umlaut-in-phphtml/#comments</comments>
		<pubDate>Sun, 19 Jul 2009 13:00:14 +0000</pubDate>
		<dc:creator>Giacomo</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP / HTML Tutorial]]></category>

		<guid isPermaLink="false">http://php.elegosproject.org/?p=113</guid>
		<description><![CDATA[So, you&#8217;ve started programming your own web application, but you found an unexpected problem: your accented letters / umlauts are displaying STRANGE things O.O
We&#8217;ll see in this tutorial on how to handle them  

By default PHP won&#8217;t handle accented characters, just like HTML does. So you&#8217;ll have to translate them in HTML equivalent codes. [...]]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;ve started programming your own web application, but you found an unexpected problem: your accented letters / umlauts are displaying STRANGE things O.O<br />
We&#8217;ll see in this tutorial on how to handle them <img src='http://php.elegosproject.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><span id="more-113"></span></p>
<p>By default PHP won&#8217;t handle accented characters, just like HTML does. So you&#8217;ll have to translate them in HTML equivalent codes. If you&#8217;re thinking &#8220;oh damn, I&#8217;ll have to handle all of them with infinite str_replace!&#8221; you&#8217;re wrong. PHP indeed has some functions that will help you doing this.</p>
<p>I firstly found this problem developing my <a title="World of Warcraft Armory SDK @ Google Code" href="http://code.google.com/p/wowasdk/" target="_blank">WoWASDK</a> classes, so I&#8217;ll take some examples from it.</p>
<h3>URLEncode</h3>
<p>This function allows you to convert the string into an URL-compatible one. This means substituting accented characters with %code. This will work if you want to create for example links (or to get an URL dynamically created)</p>
<pre class="brush: php;">// guild.wowasdk.php
class wowasdk_guild {
// cut out ...
	function __construct($region,$server,$name, $force_cache = false) {

		$server = ucfirst(strtolower($server));
		$fileurl = &quot;guilds/$region/$server/$name.xml&quot;;
		$name = urlencode($name);
</pre>
<p>Do you see? <strong>$name = urlencode($name)</strong>. This will assure you it will be URL-compatible. Not that hard <img src='http://php.elegosproject.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>utf8_decode</h3>
<p>This function will generate properly HTML characters. It&#8217;s a good way to print them off your screen in the web page.</p>
<pre class="brush: php;">// (unreleased) guild.wowasdk.php
// cut out ...
	function getMembersList($sort = GUILD_SORT_NULL) {
		$return = array();
		foreach($this-&gt;xmlsheet-&gt;guildInfo-&gt;guild-&gt;members-&gt;character as $char) {
			switch($this-&gt;region) {
				case EU:
					$url = &quot;http://eu.wowarmory.com/character-sheet.xml?&quot;;
					break;
				case US:
					$url = &quot;http://www.wowarmory.com/character-sheet.xml?&quot;;
					break;
			}
			$return[] = array(
				&quot;name&quot; =&gt; utf8_decode($char[&quot;name&quot;]),
				&quot;gender&quot; =&gt; (int)$char[&quot;genderId&quot;],
				&quot;raceid&quot; =&gt; (int)$char[&quot;raceId&quot;],
				&quot;classid&quot; =&gt; (int)$char[&quot;classId&quot;],
				&quot;level&quot; =&gt; (int)$char[&quot;level&quot;],
				&quot;rankid&quot; =&gt; (int)$char[&quot;rank&quot;],
				&quot;url&quot; =&gt; $url.$char[&quot;url&quot;],
				&quot;achPoints&quot; =&gt; (int)$char[&quot;achPoints&quot;],
			);
		}
// cut out ...</pre>
<p>Line 15 of the example: <strong>&#8220;name&#8221; => utf8_decode($char["name"])</strong>. In this case you&#8217;ll be able to handle accented chars and correctly print them in an HTML page, otherwise you&#8217;ll see strange chars.</p>
<p><strong>NOTE</strong>: if you don&#8217;t use these functions, you&#8217;ll for sure have problems even in pure PHP programs (no echo / print), this because it seems you have to &#8220;initialise&#8221; the strings before using them.</p>
<h3>htmlspecialchars</h3>
<p>At least here is the function which will translate special characters (like &#038;, <, >, &#8220;) into HTML standard ones. It&#8217;s usefull if you ecounter problems viewing your site with strange characters.</p>
<pre class="brush: php;">&lt;?php
	$string = &quot;My &lt;articulated&gt; 'string'&quot;;
	$string = htmlspecialchars($string);
	echo $string;
?&gt;</pre>
<p>Will return:</p>
<pre class="brush: xml;">My &amp;lt;articulated&amp;gt; 'string'</pre>
]]></content:encoded>
			<wfw:commentRss>http://php.elegosproject.org/2009/07/19/accented-letters-and-umlaut-in-phphtml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cycles</title>
		<link>http://php.elegosproject.org/2009/06/30/cycles/</link>
		<comments>http://php.elegosproject.org/2009/06/30/cycles/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 17:45:15 +0000</pubDate>
		<dc:creator>Giacomo</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[cycle]]></category>
		<category><![CDATA[for]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[switch]]></category>
		<category><![CDATA[while]]></category>

		<guid isPermaLink="false">http://php.elegosproject.org/?p=95</guid>
		<description><![CDATA[What are cycles? Commands repeated more than once. Is it usefull to copy/paste the same functions more than once? No.
PHP is able to avoid this, with these functions: for, while, switch, foreach.

So let&#8217;s start with an example:
&#60;?php

echo &#34;Number 1&#60;br /&#62;&#34;;
echo &#34;Number 2&#60;br /&#62;&#34;;
echo &#34;Number 3&#60;br /&#62;&#34;;
echo &#34;Number 4&#60;br /&#62;&#34;;
echo &#34;Number 5&#60;br /&#62;&#34;;
echo &#34;Number 6&#60;br /&#62;&#34;;
echo [...]]]></description>
			<content:encoded><![CDATA[<p>What are cycles? Commands repeated more than once. Is it usefull to copy/paste the same functions more than once? No.<br />
PHP is able to avoid this, with these functions: for, while, switch, foreach.</p>
<p><span id="more-95"></span></p>
<p>So let&#8217;s start with an example:</p>
<pre class="brush: php;">&lt;?php

echo &quot;Number 1&lt;br /&gt;&quot;;
echo &quot;Number 2&lt;br /&gt;&quot;;
echo &quot;Number 3&lt;br /&gt;&quot;;
echo &quot;Number 4&lt;br /&gt;&quot;;
echo &quot;Number 5&lt;br /&gt;&quot;;
echo &quot;Number 6&lt;br /&gt;&quot;;
echo &quot;Number 7&lt;br /&gt;&quot;;
echo &quot;Number 8&lt;br /&gt;&quot;;
echo &quot;Number 9&lt;br /&gt;&quot;;

?&gt;</pre>
<pre class="brush: php;">&lt;?php
for($i = 0; $i &lt; 9; $i++)
	echo &quot;Number $i&lt;br /&gt;&quot;;
?&gt;</pre>
<p>The two codes up here are exactly the same. The first one is a repeated action, the second one is the same repetition, but it&#8217;s less chaotic and better readable. This is the function <strong>for</strong>. As all the cycle functions it doesn&#8217;t require any graphs if the functions that must be executed are one, elsewise you&#8217;ll have to delimit the functions of the cycle in graphs {}. This is an example:</p>
<pre class="brush: php;">&lt;?php
for($i = 0; $i &lt; 9; $i++) {
	echo &quot;Number $i&lt;br /&gt;&quot;;
	$array[] = $i;
}
?&gt;</pre>
<p>Clear? Great.</p>
<p>Returning to the cycle function<strong>for</strong>: it&#8217;s used when you know the exact number of iterations. It requires three parameters: the starting conditional, the ending conditional and the action taken at each iteration. In the example above $i is initialised to 0, then the cycle will go on untill $i will be inferior to 9, and at each iteration $i will be incremented by one (by the way $n++ will firstly return the value of $n and then increment the variable, ++$n will do the same but in the inverse order. Think about $array[$i++] and $array[++$i]).</p>
<p>Well, after the for cycle, here it is the <strong>while</strong> one. It can be used in two different ways:</p>
<pre class="brush: php;">&lt;?php
	$found = false;
	while($found == false) {
		if( // condition //) $found = true;
		else // do something else //
	}

	do {
		// some code here
	} while($found == false);
?&gt;</pre>
<p>As you can see, the while cycle will continue untill the parameter will return TRUE (if $found is false, &#8220;$found == false&#8221; will return true!). In the first case there may be no iteration at all (if $found is true from the beginning, no iteration will be done). In the second case there will be <strong>at least</strong> one iteration, because the check is at the end of the cycle and not at the beginning.<br />
<strong>ATTENTION</strong>: the while cycle (as all the cycles) may go in a &#8220;loop&#8221;, which is a state in which the cycle will run forever. PHP is designed to stop this kind of scripts, but it may load your CPU and RAM before stopping.</p>
<p><strong>switch</strong>: is used to execute some code depending on a variable&#8217;s value. An example is far more easy to understand:</p>
<pre class="brush: php;">&lt;?php
	$myvar = //something dynamically got //;
	switch($myvar) {
		case 0:
			// do something //
			break;
		case 1:
			// do something else //
			break;
		default:
			// if none of the cases are respected,
			// the switch cycle will execute this part.
			break;
	}
?&gt;</pre>
<p>Let&#8217;s start explaining the code: the structure is switch($variable) { cases here }. Cases may be all the types of variables but not arrays, so numbers (integers, floats&#8230;), strings (single characters, phrases) and so on. There are no graphs delimiting the cases, but it&#8217;s used the function &#8220;break&#8221;, which will break indeed the cycle. If you leave the cases without the break in the end, all the functions under the &#8220;succesfull&#8221; case will be run (which isn&#8217;t what you would expect from a switch cycle). The default case is optional, and it&#8217;s the code executed when the value is not one of the scripted cases. In this case, whenever of the default case should miss, nothing will be executed.</p>
<p><strong>foreach</strong>: used to iterate for each element of a pluri-dimensional array. This is an example:</p>
<pre class="brush: php;">&lt;?php
	$data = array(
		0 =&gt; array(
			&quot;var1&quot; =&gt; &quot;a&quot;,
			&quot;var2&quot; =&gt; &quot;b&quot;,
			&quot;var3&quot; =&gt; 6,
		),
		1 =&gt; array(
			&quot;var1&quot; =&gt; &quot;g&quot;,
			&quot;var2&quot; =&gt; &quot;T&quot;,
			&quot;var3&quot; =&gt; 0,
		)
	);

	foreach($data as $case) {
		echo $case['var1'];
	}
?&gt;</pre>
<p>The syntax is foreach($variable as $newname). In this way you&#8217;ll be able to access to the elements of an array variable in a more confortable way instead of doing some maybe difficult while or for cycles (in case of strings as array indexing &#8211;> $array["my index 1"]). In this way $newname will be a new array (or value in case of mono-dimensional arrays), which will have the same behaviour of the mother array, but it will have the values of the internal arrays and not all of them. It&#8217;s normally used to access to XML files (see <a title="php.net strings page" href="http://php.elegosproject.org/2009/06/23/data-storage-read-an-xml-file/" target="_self">Data storage: read an XML file</a> for further informations about it).</p>
<p>For example here it is what $newname will be at the first iteration:</p>
<pre class="brush: php;">$newname = array(
	&quot;var1&quot; =&gt; &quot;a&quot;,
	&quot;var2&quot; =&gt; &quot;b&quot;,
	&quot;var3&quot; =&gt; 6,
);</pre>
<p>Which is the sub-array with index 0 of the mother $data.</p>
<p>It&#8217;s the most complicated cycle to understand, but indeed is pretty simple when you&#8217;ve understood it.</p>
]]></content:encoded>
			<wfw:commentRss>http://php.elegosproject.org/2009/06/30/cycles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retriving data from HTML forms</title>
		<link>http://php.elegosproject.org/2009/06/17/retriving-data-from-html-forms/</link>
		<comments>http://php.elegosproject.org/2009/06/17/retriving-data-from-html-forms/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 16:46:04 +0000</pubDate>
		<dc:creator>Giacomo</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHP / HTML Tutorial]]></category>
		<category><![CDATA[$_GET]]></category>
		<category><![CDATA[$_POST]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://php.elegosproject.org/?p=48</guid>
		<description><![CDATA[Now that we have the basics on how PHP works, let&#8217;s speak on how to get data from a form editable by a common site visitor!

You all know what I&#8217;m talking about. If you don&#8217;t, we&#8217;re going to discover how to get the data sent by the &#8220;comment form&#8221;, where you can leave a comment [...]]]></description>
			<content:encoded><![CDATA[<p>Now that we have the basics on how PHP works, let&#8217;s speak on how to get data from a form editable by a common site visitor!</p>
<p><span id="more-48"></span></p>
<p>You all know what I&#8217;m talking about. If you don&#8217;t, we&#8217;re going to discover how to get the data sent by the &#8220;comment form&#8221;, where you can leave a comment on this article!</p>
<p>Let&#8217;s start from the HTML code. We&#8217;re going to make a form to get a name, an email, a password and a comment (it&#8217;s just an example to explain the various types of data ^^).</p>
<pre class="brush: xml;">&lt;form action=&quot;myphpfile.php&quot; method=&quot;POST&quot;&gt;
	&lt;table&gt;
		&lt;tr&gt;
			&lt;td&gt;Your name:&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;name&quot; size=&quot;15&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Your password:&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;pwd&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Your email:&lt;/td&gt;&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;email&quot; /&gt;&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;td&gt;Your comment:&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/table&gt;
	&lt;textarea name=&quot;comment&quot; cols=&quot;40&quot; rows=&quot;5&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;
	&lt;input type=&quot;submit&quot; value=&quot;Send comment&quot; /&gt;
&lt;/form&gt;</pre>
<p>Ok, here we go! As you&#8217;ve seen, I used the &#8220;POST&#8221; method. The action is the page &#8220;myphpfile.php&#8221;. Note that you can use the same PHP page to show the form and to analyze the data. In this case the action will be simply &#8220;?&#8221;. You can use the POST method too, but you&#8217;ll use a different global variable (we&#8217;ll see it in a moment). Since this isn&#8217;t an HTML tutorial, I hope it&#8217;s understandable what I&#8217;ve written since here ^^.</p>
<p>You can send the same data to the same PHP file linking it in this way (you&#8217;ll use the GET method):</p>
<pre class="brush: xml;">&lt;a href=&quot;myphpfile.php?name=Giacomo&amp;pwd=blablabla&amp;email=me@mynet.com&amp;comment=cool&quot;&gt;My link&lt;/a&gt;</pre>
<p>As you can see, the GET method is not designed to send complex data. Also remember that HTML forms (both GET and POST methods) use plain text to send the data, thus I suggest you to implement a java encoder BEFORE the password and/or other sensible data are sent. We may speak about this in another tutorial.</p>
<p>Let&#8217;s see the myphpfile.php lines of code:</p>
<pre class="brush: php;">&lt;?php
	// method: GET --&gt; $_GET['variable_name']
	// the variable name is the &quot;name&quot; tag of the form's input
	$name = $_POST['name'];
	$password = $_POST['pwd'];
	$email = $_POST['email'];
	$comment = $_POST['comment'];

	// let's secure our variables
	$name = htmlspecialchars($name);
	$password = htmlspecialchars($password);
	$email = htmlspecialchars($email);
	$comment = htmlspecialchars($comment);

	if(myLoginFunction($name,$password,$email) == true) echo $comment;
	else echo &quot;Wrong login! You must log in to comment this tutorial!&quot;;
?&gt;</pre>
<p>Here it is the trick: the form you made is able to send data between it and a PHP code. PHP can handle this type of data with the global arrays (that are variables!) $_GET (in this case) and $_POST.</p>
<p><strong>A note about web security: htmlspecialchars()</strong><br />
htmlspecialchars($input) will prevent a user to post malicious code, like JavaScript, PHP or HTML code. This won&#8217;t alter the accented words (àèìòù, äëïöü and so on). This function will change the tags for example from <strong>&gt;</strong> into <strong>?&amp;gt; </strong>which is harmless for the HTML code.<br />
If you want to substitute also accented characters, you&#8217;ll need to use the function htmlentities($input), we can say an &#8220;extension&#8221; of htmlspecialchars() function.</p>
<p>Do you have any question? ^^</p>
]]></content:encoded>
			<wfw:commentRss>http://php.elegosproject.org/2009/06/17/retriving-data-from-html-forms/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Strings &amp; variables</title>
		<link>http://php.elegosproject.org/2009/06/13/strings-and-variables/</link>
		<comments>http://php.elegosproject.org/2009/06/13/strings-and-variables/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 08:12:52 +0000</pubDate>
		<dc:creator>Giacomo</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://php.elegosproject.org/?p=43</guid>
		<description><![CDATA[Why is this article called &#8220;Strings &#38; Variables&#8221;? Well, just because we&#8217;re going to speak about variables. The thing is that numbers are not that hard to use, while strings have a variety of functions, not that easy to understand on the first attempts.

Variables are what you&#8217;re going to integrate to your website. Variables are [...]]]></description>
			<content:encoded><![CDATA[<p>Why is this article called &#8220;Strings &amp; Variables&#8221;? Well, just because we&#8217;re going to speak about variables. The thing is that numbers are not that hard to use, while strings have a variety of functions, not that easy to understand on the first attempts.</p>
<p><span id="more-43"></span></p>
<p>Variables are what you&#8217;re going to integrate to your website. Variables are strings, numbers, arrays&#8230; and they can (must, I may say) interact with each other in order to output the desired result.</p>
<p><strong>Let&#8217;s start from numbers</strong>: the most common variable types are <em>integers</em> and <em>floats</em> (decimal numbers). But, as said before, variables aren&#8217;t declared but in their implementation, while in C or other languages you have to specify the type during the declaration (which you can omit it in most of the cases in PHP). Numbers can interact with each others with the normal operators + (plus), &#8211; (minus), * (multiplier), / (divisor), % (rest). The last one will output the <span style="text-decoration: underline;">rest</span> of a division, while the division will return an integer.</p>
<p>Numbers can be mixed: in this case you&#8217;ll create the most precise type, depending on your variables. For example an integer plus a float will return a float. This can be avoided <em>casting</em> the type of the result. No, we&#8217;re not going to make a film, it&#8217;s simply a way to force a type of a variable <img src='http://php.elegosproject.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  . You can cast a type just preceding the operation with the type of the desired variable in rounded parenthesis.</p>
<pre class="brush: php;">&lt;?php
	$anInteger = (integer)4+5.001; // will be 9
	$aFloatNumber = (float)4+5; // will be 9.000
?&gt;</pre>
<p>Easy, wasn&#8217;t it?</p>
<p><strong>Well, now speak a little bit about strings</strong>: they have an entire class of functions. You can know their lenght, you can capitalise them, lowerise them, take a substring, know where is the first occourrance of a substring and so on.<br />
To concatenate two different strings we use the dot operator, not the plus one.</p>
<pre class="brush: php;">&lt;php
	$string1 = &quot;Hello&quot;;
	$string2 = &quot;World&quot;;
	$string3 = $string1.&quot; &quot;.$string2.&quot;!&quot;;
?&gt;</pre>
<p>I don&#8217;t have the time to spend lots and lots of words about the string functions, they&#8217;re <span style="text-decoration: underline;">a lot</span>! You can find the list of functions (with detailed description) <a title="php.net strings page" href="http://www.php.net/strings" target="_blank">here</a>. The most important thing to understand is that a string is an array of characters. What is an array? A series of data, united under the same variable&#8217;s name. So, when for example you want to take the first three characters of a string you have to &#8220;select&#8221; object 0, 1 and 2 (arrays by the way start from 0). Here is an example:</p>
<pre class="brush: php;">&lt;?php
$abc = substr(&quot;abcdefghijklmnopqrstuwxyz&quot;,0,3); // arguments are: original string, starting point (negative values will be considered from the end of the string), optional lenght of the substring
?&gt;</pre>
<p>What about arrays? Well, they&#8217;re a more advanced variable, I&#8217;ll try to explain them with some examples, the best way to do it in my opinion. You have to know that arrays are indexed. This means that you can find a value in an array just calling its index. Index may be automatically generated by PHP, or manually set. To automatically generate the index, you don&#8217;t need to specify the index itself. But here are some examples:</p>
<pre class="brush: php;">&lt;?php
	$array1 = array(1 =&gt; &quot;a&quot;, 2 =&gt; &quot;b&quot;, 3 =&gt; &quot;c&quot;);
	$array2 = array(); // in this case I declare it first because some strict settings of PHP may print a warning in the next function
	if(!in_array(&quot;abc&quot;,$array2)) $array2[] = &quot;abc&quot;; // In this case the index is automatically generated
	$array3 = array(&quot;Riccardo&quot; =&gt; 22, &quot;Diego&quot; =&gt; 46, &quot;Elena&quot; =&gt; 33); // Yes it's not kind to tell the age of a madame, but it's a totally casual ^^

	echo $array1[2]; // b
	echo $array2[0]; // abc
	echo $array3[&quot;Diego&quot;]; // 46
?&gt;</pre>
<p>As you saw from the example, to call the variable at a certain index you use squares. You can add new variables to the existing arrays also &#8220;pushing&#8221; the variable with array_push(), and &#8220;pop&#8221; the array (eliminating the last variable in the array) using&#8230; uhm&#8230; array_pop()? ^^</p>
<p>Now make practice with the functions of strings, numbers and arrays, see you in the next tutorial!</p>
]]></content:encoded>
			<wfw:commentRss>http://php.elegosproject.org/2009/06/13/strings-and-variables/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Functions</title>
		<link>http://php.elegosproject.org/2009/06/10/functions/</link>
		<comments>http://php.elegosproject.org/2009/06/10/functions/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 22:12:03 +0000</pubDate>
		<dc:creator>Giacomo</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[creation of functions]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://php.elegosproject.org/?p=29</guid>
		<description><![CDATA[Here is the basic tutorial (I may call it: basic guide) about functions! In this article I&#8217;m going to explain what are the functions and how to create them too!
PHP is based on functions. Without functions you couldn&#8217;t combine and express your variables. So it can be defined as the hinge of PHP.
As you may [...]]]></description>
			<content:encoded><![CDATA[<p>Here is the basic tutorial (I may call it: basic guide) about functions! In this article I&#8217;m going to explain what are the functions and how to create them too!<span id="more-29"></span></p>
<p>PHP is based on functions. Without functions you couldn&#8217;t combine and express your variables. So it can be defined as the hinge of PHP.</p>
<p>As you may correctly think, functions &#8220;do something&#8221;. Starting from the easiest &#8220;print&#8221; to the more complex socket opening or image generation.</p>
<p>First of all: all the functions require arguments, from zero up to a lot of them. Functions are called in this way:<div><div class="wp-synhighlighter-expanded"><a name="#codesyntax1"></a><a style="wp-synhighlighter-title" href="#codesyntax1"  onClick="javascript:wpContainer=this.parentNode.parentNode.getElementsByTagName('div')[1];	if(wpContainer.style.display=='none') {wpContainer.style.display=''; this.parentNode.className='wp-synhighlighter-expanded'} 	else {wpContainer.style.display='none'; this.parentNode.className='wp-synhighlighter-collapsed'}">Code</a></div><div class="wp-synhighlighter-inner"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">function(arg1, arg2, arg3);</div></li></ol></pre></div></div>Just like most of the programming languages (C, Java and so on).</p>
<p>Arguments are variables which can be defined &#8220;on the fly&#8221; or previously set and then put as them. For the first example, I&#8217;m going to print two strings, equals to each other, in these two different ways:</p>
<div><div class="wp-synhighlighter-expanded"><a name="#codesyntax2"></a><a style="wp-synhighlighter-title" href="#codesyntax2"  onClick="javascript:wpContainer=this.parentNode.parentNode.getElementsByTagName('div')[1];	if(wpContainer.style.display=='none') {wpContainer.style.display=''; this.parentNode.className='wp-synhighlighter-expanded'} 	else {wpContainer.style.display='none'; this.parentNode.className='wp-synhighlighter-collapsed'}">Code</a></div><div class="wp-synhighlighter-inner"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">&lt;?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$welcome</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hello World!&quot;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><a href="http://www.php.net/print"><span style="color: #990000;">print</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello World!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// direct</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><a href="http://www.php.net/print"><span style="color: #990000;">print</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$welcome</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?&gt;</span></div></li></ol></pre></div></div>
<p>By the way, // means a comment on a single line while /* comment here */ means a comment in multi lines.<br />
In this case the print function requires one argument, which can be an integer, float, array, string&#8230; it doesn&#8217;t matter, PHP is cool <img src='http://php.elegosproject.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  . As you can see the potential of PHP is to get a data, edit it, combine it with other data, recollect other informations and output the final code. In this way you can just imagine the dynamic potentials of PHP versus a static HTML web page.</p>
<p>Some functions require some arguments as the others do, but sometime they may be able to accept extra arguments. They&#8217;re set by default and thus can be omitted in the function call, but can be changed if necessary. An example of these functions is <a title="fsockopen php.net page" href="http://www.php.net/fsockopen" target="_blank">fsockopen</a>, which is able to open a connection to another server (i.e. for pinging a game-server or to establish a plain text / binary transmission between two services&#8230; don&#8217;t bother about it (for now)!):<br />
<div><div class="wp-synhighlighter-expanded"><a name="#codesyntax3"></a><a style="wp-synhighlighter-title" href="#codesyntax3"  onClick="javascript:wpContainer=this.parentNode.parentNode.getElementsByTagName('div')[1];	if(wpContainer.style.display=='none') {wpContainer.style.display=''; this.parentNode.className='wp-synhighlighter-expanded'} 	else {wpContainer.style.display='none'; this.parentNode.className='wp-synhighlighter-collapsed'}">Code</a></div><div class="wp-synhighlighter-inner"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;">resource fsockopen ( string $hostname [, int $port= -1 [, int &amp;$errno [, string &amp;$errstr [, float $timeout= ini_get(&quot;default_socket_timeout&quot;) ]]]] )</div></li></ol></pre></div></div><br />
Well, all the arguments in squares [] are optional arguments. For example, I want to ping my web server (port: 80, default value of the argument), then my FTP server (port 21). Here is the code:</p>
<div><div class="wp-synhighlighter-expanded"><a name="#codesyntax4"></a><a style="wp-synhighlighter-title" href="#codesyntax4"  onClick="javascript:wpContainer=this.parentNode.parentNode.getElementsByTagName('div')[1];	if(wpContainer.style.display=='none') {wpContainer.style.display=''; this.parentNode.className='wp-synhighlighter-expanded'} 	else {wpContainer.style.display='none'; this.parentNode.className='wp-synhighlighter-collapsed'}">Code</a></div><div class="wp-synhighlighter-inner"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">&lt;?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$web</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fsockopen"><span style="color: #990000;">fsockopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php.elegosproject.org&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$ftp</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/fsockopen"><span style="color: #990000;">fsockopen</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;php.elegosproject.org&quot;</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">21</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?&gt;</span></div></li></ol></pre></div></div>
<p>If I want to know if something goes wrong, I may specify $errno and $errstr, two variables that are set in case of errors, but this function is very complex, it was just an example on how optional arguments work ^^.</p>
<p>So, functions may edit variables, but most commonly they return <em>something</em>. For example the function rand, saw for the first time in the <a title="ABC of PHP" href="http://php.elegosproject.org/2009/06/09/abc-of-php/" target="_self">ABC of PHP</a> article, returns an integer (which is a number).</p>
<p>Generally in other program languages, like C, when you create a function you have to declare what type of variable will return. In PHP there is no need to do it, as all the variables are treated in the same way!</p>
<p>To create a function you have simply to&#8230; write it! just with this structure:</p>
<div><div class="wp-synhighlighter-expanded"><a name="#codesyntax5"></a><a style="wp-synhighlighter-title" href="#codesyntax5"  onClick="javascript:wpContainer=this.parentNode.parentNode.getElementsByTagName('div')[1];	if(wpContainer.style.display=='none') {wpContainer.style.display=''; this.parentNode.className='wp-synhighlighter-expanded'} 	else {wpContainer.style.display='none'; this.parentNode.className='wp-synhighlighter-collapsed'}">Code</a></div><div class="wp-synhighlighter-inner"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">&lt;?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">function</span> myFunction<span style="color: #009900;">&#40;</span><span style="color: #000088;">$myArg1</span><span style="color: #339933;">,</span> <span style="color: #000088;">$myArg2</span><span style="color: #339933;">,</span> <span style="color: #000088;">$myArg3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #666666; font-style: italic;">// my operations here</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">return</span> <span style="color: #000088;">$myVariable</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//can also not return at all, in that case omit this line </span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#125;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?&gt;</span></div></li></ol></pre></div></div>
<ol>
<li>Functions require arguments, but if your function requires no arguments, simply leave the parenthesis void -&gt; function myFunction()</li>
<li>All the code of the function is closed in the graphs {}: it&#8217;s a separate environment, and thus you won&#8217;t be able to use local variables declared in the main body of your script, but only global ones (like $_SERVER, $_POST, $_GET and so on) and local ones declared in the function (or arguments passed to the function, but pay attention: they are only COPIES of the original variables!).</li>
<li>A function may return something. In this case, &#8220;return $whatToReturn&#8221; will be written, generally at the end of the function: in fact nothing of the function will be processed after the &#8220;return line&#8221;, so pay attention!</li>
</ol>
<p>Here is an example of a very stupid function:</p>
<div><div class="wp-synhighlighter-expanded"><a name="#codesyntax6"></a><a style="wp-synhighlighter-title" href="#codesyntax6"  onClick="javascript:wpContainer=this.parentNode.parentNode.getElementsByTagName('div')[1];	if(wpContainer.style.display=='none') {wpContainer.style.display=''; this.parentNode.className='wp-synhighlighter-expanded'} 	else {wpContainer.style.display='none'; this.parentNode.className='wp-synhighlighter-collapsed'}">Code</a></div><div class="wp-synhighlighter-inner"><pre class="php" style="font-family:monospace;"><ol><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">&lt;?php</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">function</span> getNameSurname<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span><span style="color: #000088;">$surname</span><span style="color: #339933;">,</span> <span style="color: #000088;">$sex</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/strtolower"><span style="color: #990000;">strtolower</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sex</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;m&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Mister&quot;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">else</span> <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Missus&quot;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: bold; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #b1b100;">return</span> <span style="color: #000088;">$title</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$name</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$surname</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #009900;">&#125;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> getNameSurname<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Giacomo&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Furlan&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><a href="http://www.php.net/print"><span style="color: #990000;">print</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// will print &quot;Mister Giacomo Furlan&quot;</span></div></li><li style="font-weight: normal; vertical-align:top;"><div style="font: normal normal 1em/1.2em monospace; margin:0; padding:0; background:none; vertical-align:top;"><span style="color: #000000; font-weight: bold;">?&gt;</span></div></li></ol></pre></div></div>
<p>In this case the function will require $name and $surname. If $sex is not specified, male will be the default one. Strtolower is a function which makes a string all in lower case (easier to handle in these cases where case sensitivity is not required). Then the function concatenates the sex title, the name and the surname. Thus this function will return a string. The script will eventually call this function and echo the result. Easy, wasn&#8217;t it? (don&#8217;t bother about if else cycle, I&#8217;ll speak about it in another tutorial).</p>
]]></content:encoded>
			<wfw:commentRss>http://php.elegosproject.org/2009/06/10/functions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ABC of PHP</title>
		<link>http://php.elegosproject.org/2009/06/09/abc-of-php/</link>
		<comments>http://php.elegosproject.org/2009/06/09/abc-of-php/#comments</comments>
		<pubDate>Mon, 08 Jun 2009 22:52:29 +0000</pubDate>
		<dc:creator>Giacomo</dc:creator>
				<category><![CDATA[Basic]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[float]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[integer]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://php.elegosproject.org/?p=3</guid>
		<description><![CDATA[OK, first of all: sorry for the bad article&#8217;s title, but it&#8217;s concise and perfect for the purpose of this first and simple tutorial. Today we&#8217;re going to discover the simplicity of PHP, the basic structure and functions.
Before starting, here is a simple example:
&#60;html&#62;
	&#60;head&#62;
		&#60;title&#62;My first PHP code!&#60;/title&#62;
	&#60;/head&#62;
	&#60;body&#62;
		Hello! This is a plain HTML text. I can't [...]]]></description>
			<content:encoded><![CDATA[<p>OK, first of all: sorry for the bad article&#8217;s title, but it&#8217;s concise and perfect for the purpose of this first and simple tutorial. Today we&#8217;re going to discover the simplicity of PHP, the basic structure and functions.</p>
<p><span id="more-3"></span>Before starting, here is a simple example:</p>
<pre class="brush: php;">&lt;html&gt;
	&lt;head&gt;
		&lt;title&gt;My first PHP code!&lt;/title&gt;
	&lt;/head&gt;
	&lt;body&gt;
		Hello! This is a plain HTML text. I can't modify it without editing the page itself! (even if I like the block notes <img src='http://php.elegosproject.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )&lt;br /&gt;
		&lt;?php
			$message = &quot;Hello! This is a (potential) dynamic string!&quot;;
			$simpleNumber = 7;
			echo $message.&quot;&lt;br /&gt; I really like number &quot;.$simpleNumber.&quot;!&quot;;
		?&gt;
	&lt;/body&gt;
&lt;/html&gt;</pre>
<p>This code will reproduce this output:</p>
<blockquote><p><em>Hello! This is a plain HTML text. I can&#8217;t modify it without editing the page itself! (even if I like the block notes <img src='http://php.elegosproject.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> )<br />
Hello! This is a (potential) dynamic string!<br />
I really like number 7!</em></p></blockquote>
<p>Let&#8217;s start explaining!</p>
<p>First of all, PHP means &#8220;<em>Personal Home Page</em>&#8220;. Yes, you read it correctly: it was initially designed to create simple and (specially) dynamic web pages. During its development PHP become a more and more popular web scripting language and today is one of the most used languages for internet applications, including classes support (PHP5), database access (MySQL but not only), file reading/writing and so on. To demonstrate the power of PHP you could even create an IRC bot with it! Because of its simplicity it&#8217;s also easy to understand and to learn.</p>
<p>As you may see in the codebox, PHP code is closed between &#8220;<strong>&lt;?php</strong>&#8221; and &#8220;<strong>?&gt;</strong>&#8220;. A more standard implementation of it would require &#8220;?php&gt;&#8221; as the ending tag, but nowadays all the web servers recognise just &#8220;?&gt;&#8221;. When you call this tag you won&#8217;t be able to use simple HTML code, you&#8217;ll need to &#8220;print&#8221; it if you want to use it in the &#8220;PHP space&#8221;.</p>
<p>Usually PHP is embedded in the HTML code. Please note that you can create an entire site using pure PHP and ignoring the <em>HEAD</em> and <em>BODY</em> HTML tags, but I allways suggest you to use them in order to produce a standard HTML web page: in fact PHP code will run server-side and will produce plain HTML code, because it&#8217;s the only code a browser will ever decode and show you correctly.</p>
<p>Web pages with PHP inside must be named with the extension &#8220;.php&#8221;: in this way the web server will recognise them and elaborate them; otherwise the web server will show the code instead of the desired output. Another requirement is that the web server handles PHP correctly: it&#8217;s usually written in the website of the hoster. A few italian free web hosting services I used (and still use) are <a title="Official Netsons homepage (italian hosting)" href="http://www.netsons.com/" target="_blank">Netsons</a> and <a title="Altervista official homepage (italian hosting)" href="http://it.altervista.org/" target="_blank">Altervista</a>; find your free hosting on <a title="Google search &quot;free web hosting php&quot;" href="http://www.google.it/search?q=free+web+hosting+php&amp;ie=utf-8&amp;oe=utf-8&amp;aq=t&amp;rls=org.mozilla:it:official&amp;client=firefox-a" target="_blank">google</a>!</p>
<p>All the commands are followed by a comma, this because it enables you to create complex commands in more than one line. Don&#8217;t worry, I too miss them sometimes! The PHP engine will warn you about them and stop executing the script.</p>
<p><strong>Variables</strong> are all the parts in the code starting with <strong>$</strong>. There are several types of variables, from the local ones (just the ones you see in the code) to the global ones (like <em>$_GET</em>, <em>$_POST</em> or <em>$_SERVER</em>) which are defined by default in the PHP environment and you can&#8217;t modify them (but we&#8217;ll see them later in another tutorial). They are automatically recognised by the PHP engine: this means you can write a string (which is a text variable) without declaring it before (remember in C++? string sString = &#8220;blablabla&#8221;), you can save a number, a float (decimal int, i.e. 1.002) and so on <em>&#8220;just writing it&#8221;</em>.</p>
<p>To declare a variable use the &#8220;=&#8221; operator, to compare two of them (or one of them and a constant) you&#8217;ll use &#8220;==&#8221; in most of the cases.</p>
<pre class="brush: php;">&lt;?php
	$integer = 6;
	$string = &quot;bla bla bla&quot;;
	$float = 1.002;
?&gt;</pre>
<p>Let&#8217;s speak a little bit about <strong>strings</strong>: you can concatenate strings with other strings or numbers. The &#8220;magical&#8221; operation is made by the &#8220;dot operator&#8221; (.). In this way you can mix static with dynamic variables in order to create dynamic contents. In PHP you can mix strings with all the other types of variables. Here is an example:</p>
<pre class="brush: php;">&lt;?php
	$string1 = &quot;Hello &quot;;
	$name = $_POST['name'];
	$random_number = rand(0,100);
	echo $string1.$name.&quot;! Here is your number: &quot;.$random_number;
?&gt;</pre>
<p>As you can see here we&#8217;ve concatenated a local string ($string1), a global variable ($name, $_POST is taken from an HTML form (variable &#8216;name&#8217;) with method POST and as action the PHP page) and a number (rand is used to generate randomic numbers, it&#8217;s a function and we&#8217;ll see it in a moment). Of course there are several functions for strings, they&#8217;re the most elaborated variables of all PHP, I&#8217;ll dedicate an entire tutorial on them.</p>
<p><strong>Numbers</strong>: as said before numbers can be integers, floats and so on. Just declare them as usual! (see the variables example code). You can sum, subtract, divide or multiply them with the standard operators: + (sum), &#8211; (subtraction), / (division), * (moltiplication). Nothing less, nothing more ^^</p>
<p><strong>Functions</strong>: one of the most difficult things to <em>&#8220;tame&#8221;</em> in PHP. The most difficult part is indeed to know them, they&#8217;re as easy as breathing (you&#8217;ll say: this man is crazy!). You have just to make some practice!<br />
Functions are piece of code pre-written for you. They may need <em>arguments</em>: they are contained in the parenthesis next to the function name. We have just seen an example of function: rand($int,$int). Rand is used to generate randomic numbers and requires two arguments: the minimal and the maximal number. You can see a list of function on the <a title="php.net, official PHP website" href="http://www.php.net" target="_blank">php.net</a> website. Don&#8217;t worry about this: following my tutorials you won&#8217;t need to explore it (it&#8217;s HUGE!), in the future, if you&#8217;ll have to search for a function, you&#8217;ll know at least how it may be called the function and thus your search will be fast.</p>
<p>A particular function which needs an argument but not in parenthesis is <em>echo</em>: it requires a variable (of all the types), but just writing it after its calling:</p>
<pre class="brush: php;">&lt;?php
	echo &quot;Hello World!&quot;;
?&gt;</pre>
<p>Of course if it disturbs you, you can allways the more-standard function <em>print</em>, which has nothing different then the function above:</p>
<pre class="brush: php;">&lt;?php
	print(&quot;Hello World!&quot;);
?&gt;</pre>
<p>As of my experience, echo is faster to write down and, using a highlighting program like <a title="Smultron official homepage" href="http://tuppis.com/smultron/" target="_blank">Smultron</a>* (for MacOS), <a title="NotePad++ official homepage" href="http://notepad-plus.sourceforge.net/" target="_blank">NotePad++</a>* (for Windows) or GEdit* / Kate* (for Linux) there is no risk to forget quotes opened. Honestly I started writing PHP with <a title="Adobe Dreamweaver's official homepage" href="http://www.adobe.com/products/dreamweaver/" target="_blank">Adobe (Macromedia) Dreamweaver</a>, but I suggest you to try writing directly the source, you&#8217;ll learn 200% faster!</p>
<p>What have you learnt since the beginning?</p>
<ol>
<li>What PHP is and how it&#8217;s called within an HTML web page</li>
<li>How are variables declared</li>
<li>How to print them in the HTML document</li>
<li>How to interact with them</li>
<li>What functions are and how to use them</li>
<li>What programs to use to write in PHP</li>
</ol>
<p>* they are all free and opensource, download them for free!</p>
<p>Now download a PHP editor (or just use the BlockNotes) and start practising!</p>
<p>Giacomo</p>
]]></content:encoded>
			<wfw:commentRss>http://php.elegosproject.org/2009/06/09/abc-of-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
