<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1246969963583076690</id><updated>2011-11-27T20:18:23.500-03:00</updated><category term='programacion script'/><category term='Estructuras de control'/><category term='Syntax'/><category term='Data Types'/><category term='Sintaxis'/><category term='constants'/><category term='General'/><category term='tipo de datos'/><category term='Control Structures'/><category term='Variables'/><category term='Operators'/><title type='text'>My Free World - PHP</title><subtitle type='html'>All Php and Mysql. Web design. Programming PHP. PHP Tutorial. PHP. Programming. Php Scripts. Dynamic Web Pages. Mysql. Mysql database.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>56</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1835877807373760962</id><published>2008-12-26T17:11:00.000-02:00</published><updated>2008-12-26T17:12:29.204-02:00</updated><title type='text'></title><content type='html'>I was designed and programmed with a php website to download tutorials. Although yet to add new development and programming tutorials, you can find and download a php &lt;a href="http://tutorial-download.com" target="_blank"&gt;&lt;span style="font-weight: bold;"&gt;tutorial&lt;/span&gt;&lt;/a&gt; if you need it.&lt;br /&gt;The tutorials in pdf format, are completely free.&lt;br /&gt;This is my small contribution to the programmers who need to document some programming languages. I hope you like it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1835877807373760962?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1835877807373760962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1835877807373760962' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1835877807373760962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1835877807373760962'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/12/i-was-designed-and-programmed-with-php.html' title=''/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4855678806371640211</id><published>2008-07-15T13:07:00.000-03:00</published><updated>2008-07-15T13:08:57.737-03:00</updated><title type='text'>42 tips for optimizing your php code</title><content type='html'>•  If a method can be static, declare it static. Speed improvement is by a factor of 4.&lt;br /&gt;•  echo is faster than print.&lt;br /&gt;•  Use echo's multiple parameters instead of string concatenation.&lt;br /&gt;•  Set the maxvalue for your for-loops before and not in the loop.&lt;br /&gt;•  Unset your variables to free memory, especially large arrays.&lt;br /&gt;•  Avoid magic like __get, __set, __autoload&lt;br /&gt;•  require_once() is expensive&lt;br /&gt;•  Use full paths in includes and requires, less time spent on resolving the OS paths.&lt;br /&gt;•  If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()&lt;br /&gt;•  See if you can use strncasecmp, strpbrk and stripos instead of regex&lt;br /&gt;•  str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4&lt;br /&gt;•  If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.&lt;br /&gt;•  It's better to use switch statements than multi if, else if, statements.&lt;br /&gt;•  Error suppression with @ is very slow.&lt;br /&gt;•  Turn on apache's mod_deflate&lt;br /&gt;•  Close your database connections when you're done with them&lt;br /&gt;•  $row[’id’] is 7 times faster than $row[id]&lt;br /&gt;•  Error messages are expensive&lt;br /&gt;•  Do not use functions inside of for loop, such as for ($x=0; $x &lt; count($array); $x) The count() function gets called each time.&lt;br /&gt;•  Incrementing a local variable in a method is the fastest. Nearly the same as calling a local variable in a function.&lt;br /&gt;•  Incrementing a global variable is 2 times slow than a local var.&lt;br /&gt;•  Incrementing an object property (eg. $this-&gt;prop++) is 3 times slower than a local variable.&lt;br /&gt;•  Incrementing an undefined local variable is 9-10 times slower than a pre-initialized one.&lt;br /&gt;•  Just declaring a global variable without using it in a function also slows things down (by about the same amount as incrementing a local var). PHP probably does a check to see if the global exists.&lt;br /&gt;•  Method invocation appears to be independent of the number of methods defined in the class because I added 10 more methods to the test class (before and after the test method) with no change in performance.&lt;br /&gt;•  Methods in derived classes run faster than ones defined in the base class.&lt;br /&gt;•  A function call with one parameter and an empty function body takes about the same time as doing 7-8 $localvar++ operations. A similar method call is of course about 15 $localvar++ operations.&lt;br /&gt;•  Surrounding your string by ' instead of " will make things interpret a little faster since php looks for variables inside "..." but not inside '...'. Of course you can only do this when you don't need to have variables in the string.&lt;br /&gt;•  When echoing strings it's faster to separate them by comma instead of dot. Note: This only works with echo, which is a function that can take several strings as arguments. &lt;br /&gt;•  A PHP script will be served at least 2-10 times slower than a static HTML page by Apache. Try to use more static HTML pages and fewer scripts.&lt;br /&gt;•  Your PHP scripts are recompiled every time unless the scripts are cached. Install a PHP caching product to typically increase performance by 25-100% by removing compile times.&lt;br /&gt;•  Cache as much as possible. Use memcached - memcached is a high-performance memory object caching system intended to speed up dynamic web applications by alleviating database load. OP code caches are useful so that your script does not have to be compiled on every request&lt;br /&gt;•  When working with strings and you need to check that the string is either of a certain length you'd understandably would want to use the strlen() function. This function is pretty quick since it's operation does not perform any calculation but merely return the already known length of a string available in the zval structure (internal C struct used to store variables in PHP). However because strlen() is a function it is still somewhat slow because the function call requires several operations such as lowercase &amp; hashtable lookup followed by the execution of said function. In some instance you can improve the speed of your code by using an isset() trick.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Ex. &lt;br /&gt;&lt;br /&gt;if (strlen($foo) &lt; 5) { echo "Foo is too short"; }&lt;br /&gt;&lt;br /&gt;vs.&lt;br /&gt;&lt;br /&gt;if (!isset($foo{5})) { echo "Foo is too short"; }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Calling isset() happens to be faster then strlen() because unlike strlen(), isset() is a language construct and not a function meaning that it's execution does not require function lookups and lowercase. This means you have virtually no overhead on top of the actual code that determines the string's length.&lt;br /&gt;•  When incrementing or decrementing the value of the variable $i++ happens to be a tad slower then ++$i. This is something PHP specific and does not apply to other languages, so don't go modifying your C or Java code thinking it'll suddenly become faster, it won't. ++$i happens to be faster in PHP because instead of 4 opcodes used for $i++ you only need 3. Post incrementation actually causes in the creation of a temporary var that is then incremented. While pre-incrementation increases the original value directly. This is one of the optimization that opcode optimized like Zend's PHP optimizer. It is a still a good idea to keep in mind since not all opcode optimizers perform this optimization and there are plenty of ISPs and servers running without an opcode optimizer.&lt;br /&gt;•  Not everything has to be OOP, often it is too much overhead, each method and object call consumes a lot of memory. &lt;br /&gt;•  Do not implement every data structure as a class, arrays are useful, too&lt;br /&gt;•  Don't split methods too much, think, which code you will really re-use&lt;br /&gt;•  You can always split the code of a method later, when needed&lt;br /&gt;•  Make use of the countless predefined functions&lt;br /&gt;•  If you have very time consuming functions in your code, consider writing them as C extensions&lt;br /&gt;•  Profile your code. A profiler shows you, which parts of your code consumes how many time. The Xdebug debugger already contains a profiler. Profiling shows you the bottlenecks in overview&lt;br /&gt;•  mod_gzip which is available as an Apache module compresses your data on the fly and can reduce the data to transfer up to 80%&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4855678806371640211?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4855678806371640211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4855678806371640211' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4855678806371640211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4855678806371640211'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/07/42-tips-for-optimizing-your-php-code.html' title='42 tips for optimizing your php code'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-3786064693710280871</id><published>2008-07-02T09:46:00.000-03:00</published><updated>2008-07-02T09:47:33.333-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='constants'/><title type='text'>Php Magic constants</title><content type='html'>&lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;PHP provides a large number of predefined constants to any script which it runs. Many of these constants, however, are created by various extensions, and will only be present when those extensions are available, either via dynamic loading or because they have been compiled in. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;There are five magical constants that change depending on where they are used. For example, the value of &lt;b&gt;__LINE__&lt;/b&gt; depends on the line that it's used on in your script. These special constants are case-insensitive and are as follows: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;a name="id2537590"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;A few "magical" PHP constants&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="" border="1" cellpadding="0"&gt;  &lt;thead&gt;   &lt;tr style=""&gt;    &lt;td style="padding: 0.75pt;"&gt;    &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;    &lt;/td&gt;    &lt;td style="padding: 0.75pt;"&gt;    &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Description&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;    &lt;/td&gt;   &lt;/tr&gt;  &lt;/thead&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;__LINE__&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;The current line number of the file. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;__FILE__&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;The full path and filename of the file.   If used inside an include, the name of the included file is returned. Since   PHP 4.0.2, &lt;b&gt;__FILE__&lt;/b&gt; always contains an absolute path whereas in older   versions it contained relative path under some circumstances. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;__FUNCTION__&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;The function name. (Added in PHP 4.3.0)   As of PHP 5 this constant returns the function name as it was declared   (case-sensitive). &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;In PHP 4 its value is always lowercased. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;__CLASS__&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;The class name. (Added in PHP 4.3.0) As   of PHP 5 this constant returns the class name as it was declared   (case-sensitive). &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;In PHP 4 its value is always lowercased. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;__METHOD__&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;The class method name. (Added in PHP   5.0.0) The method name is returned as it was declared (case-sensitive). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-3786064693710280871?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/3786064693710280871/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=3786064693710280871' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3786064693710280871'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3786064693710280871'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/07/php-magic-constants.html' title='Php Magic constants'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-3053279041938117377</id><published>2008-07-02T09:42:00.001-03:00</published><updated>2008-07-02T09:44:44.641-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Operators'/><title type='text'>Php Error Control Operators</title><content type='html'>&lt;span style=";font-family:arial;font-size:100%;"  &gt;PHP supports one error control operator: the at sign (@). When prepended to an expression in PHP, any error messages that might be generated by that expression will be ignored.&lt;br /&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;If the track_errors feature is enabled, any error message generated by the expression will be saved in the variable $php_errormsg. This variable will be overwritten on each error, so check early if you want to use it. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;    &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;/* Intentional file error */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;$my_file = @file ('non_existent_file') or&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;&lt;span style=""&gt;    &lt;/span&gt;die ("Failed opening file: error was '$php_errormsg'");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;// this works for any expression, not just functions:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;$value = @$cache[$key]; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;// will not issue a notice if the index $key doesn't exist.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;br /&gt;Note: The @-operator works only on expressions. A simple rule of thumb is: if you can take the value of something, you can prepend the @ operator to it. For instance, you can prepend it to variables, function and include() calls, constants, and so forth. You cannot prepend it to function or class definitions, or conditional structures such as if and foreach, and so forth. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;Warning &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoNormal" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=";font-size:10;color:black;"  lang="EN" &gt;Currently the "@" error-control operator prefix will even disable error reporting for critical errors that will terminate script execution. Among other things, this means that if you use "@" to suppress errors from a certain function and either it isn't available or has been mistyped, the script will die right there with no indication as to why. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-3053279041938117377?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/3053279041938117377/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=3053279041938117377' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3053279041938117377'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3053279041938117377'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/07/php-error-control-operators.html' title='Php Error Control Operators'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-7617113856463974831</id><published>2008-05-08T20:53:00.001-03:00</published><updated>2008-05-08T20:53:59.417-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Reasons to Love PHP and MySQL</title><content type='html'>There are ever so many reasons to love PHP and MySQL. Let us count a few. &lt;p style="margin-bottom: 0cm;"&gt;Cost&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;PHP costs you nothing. Zip, zilch, nada, not one red cent. Nothing up front, nothing over the lifetime of the application, nothing when it’s over. Did we mention that the Apache/PHP/MySQL combo runs great on cheap, low-end hardware that you couldn’t even think about for IIS/ASP/SQL Server?&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;MySQL is a slightly different animal in its licensing terms. Before you groan at the concept of actually using commercial software, consider that although MySQL is open-source licensed for many uses, it is not and has never been primarily community-developed software. MySQL AB is a commercial entity with necessarily commercial interests. Unlike typical open source projects, where developers often have regular full-time (and paying) day jobs in addition to their freely given open source efforts, the MySQL developers derive their primary income from the project. There are still many circumstances in which MySQL can be used for free (basically anything nonredistributive, which covers most PHP-based projects), but if you make money developing solutions that use MySQL, consider buying a license or a support&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;contract. It’s still infinitely more reasonable than just about any software license you will ever pay for.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;For purposes of comparison, Table 1-1 shows some current retail figures for similar products in the United States. All prices quoted are for a single-processor public Web server with the most common matching database and development tool; $0 means a no-cost alternative is a common real-world choice.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Comparative Out-of-Pocket Costs&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;ASP/SQL ColdFusion&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Item Server MX/SQL Server JSP/Oracle PHP/MySQL&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Development tool $0–2499 $599 $0–~2000 $0–249&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Server $999 $2298 $0–~35,000 $0&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;RDBMS $4999 $4999 $15,000 $0–220&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;   &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Open source software: don’t fear the cheaper&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;But as the bard so pithily observed, we are living in a material world —where we’ve internalized maxims such as, “You get what you pay for,” “There’s no such thing as a free lunch,” and “Things that sound too good to be true usually are.” You (or your boss) may, therefore, have some lingering doubts about the quality and viability of no-cost software. It probably doesn’t help that until recently software that didn’t cost money — formerly called freeware , shareware, or free software — was generally thought to fall into one of three categories:&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Programs filling small, uncommercial niches&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Programs performing grungy, low-level jobs&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Programs for people with bizarre socio-political issues&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;It’s time to update some stereotypes once and for all. We are clearly in the middle of a sea change in the business of software. Much (if not most) major consumer software is distributed without cost today; e-mail clients, Web browsers, games, and even full-service office suites are all being given away as fast as their makers can whip up Web versions or set up  &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;FTP servers. Consumer software is increasingly seen as a loss-leader, the flower that attracts the pollinating honeybee — in other words, a way to sell more server hardware, operating systems, connectivity, advertising, optional widgets, or stock shares. The full retail price of a piece of software, therefore, is no longer a reliable gauge of its quality or the eccentricity-level of its user.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;On the server side, open source products have come on even stronger. Not only do they&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;compete with the best commercial stuff; in many cases there’s a feeling that they far exceed the competition. Don’t take our word for it! Ask IBM, any hardware manufacturer, NASA, Amazon.com, Rockpointe Broadcasting, Ernie Ball Corporation, the Queen of England, or the Mexican school system. If your boss still needs to be convinced, further ammunition is available at www.opensource.org and www.fsf.org.&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-7617113856463974831?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/7617113856463974831/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=7617113856463974831' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7617113856463974831'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7617113856463974831'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/05/reasons-to-love-php-and-mysql.html' title='Reasons to Love PHP and MySQL'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-6835090722453904512</id><published>2008-05-08T20:50:00.001-03:00</published><updated>2008-05-08T20:50:20.195-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>The History of MySQL</title><content type='html'>Depending on how much detail you want, the history of MySQL can be traced as far back as 1979, when MySQL’s creator, Monty Widenius, worked for a Swedish IT and data consulting firm, TcX. While at TcX, Monty authored UNIREG, a terminal interface builder that connected to raw ISAM data stores. In the intervening 15 years, UNIREG served its makers rather well through a series of translations and extensions to accommodate increasingly large data sets. &lt;p style="margin-bottom: 0cm;"&gt;In 1994, when TcX began working on Web data applications, chinks in the UNIREG armor, primarily having to do with application overhead, began to appear. This sent Monty and his colleagues off to look for other tools. One they inspected rather closely was Hughes mSQL, a light and zippy database application developed by David Hughes. mSQL possessed the distinct advantages of being inexpensive and somewhat entrenched in the market, as well as featuring a fairly well-developed client API. The 1.0 series of mSQL release lacked indexing, however, a feature crucial to performance with large data stores. Although the 2.0 series of mSQL would see the addition of this feature, the particular implementation used was not compatible with UNIREG’s B+-based features. At this point, MySQL, at least conceptually, was born.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Monty and TcX decided to start with the substantial work already done on UNIREG while developing a new API that was substantially similar to that used by mSQL, with the exception of the more effective UNIREG indexing scheme. By early 1995, TcX had a 1.0 version of this new product ready. They gave it the moniker MySQL and later that year released it under a combination open source and commercial licensing scheme that allowed continued development of the product while providing a revenue stream for MySQL AB, the company that evolved from TcX.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Over the past ten years, MySQL has truly developed into a world class product. MySQL now competes with even the most feature-rich commercial database applications such as Oracle and Informix. Additions in the 4.x series have included much-requested features such as transactions and foreign key support. All this has made MySQL the world’s most used open source database.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-6835090722453904512?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/6835090722453904512/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=6835090722453904512' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/6835090722453904512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/6835090722453904512'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/05/history-of-mysql.html' title='The History of MySQL'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-7211909930889508997</id><published>2008-05-08T20:47:00.000-03:00</published><updated>2008-05-08T20:48:24.887-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>The History of PHP</title><content type='html'>Rasmus Lerdorf— software engineer, Apache team member, and international man of mystery — is the creator and original driving force behind PHP. The first part of PHP was devel-oped for his personal use in late 1994. This was a CGI wrapper that helped him keep track of people who looked at his personal site. The next year, he put together a package called the Personal Home Page Tools (a.k.a. The PHP Construction Kit) in response to demand from users who had stumbled into his work by chance or word of mouth. Version 2 was soon released under the title PHP/FI and included the Form Interpreter, a tool for parsing SQL queries. &lt;p style="margin-bottom: 0cm;"&gt;By the middle of 1997, PHP was being used on approximately 50,000 sites worldwide. It was clearly becoming too big for any single person to handle, even someone as focused and energetic as Rasmus. A small core development team now runs the project on the open source “benevolent junta” model, with contributions from developers and users around the world.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Zeev Suraski and Andi Gutmans, the two Israeli programmers who developed the PHP3 and&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;PHP4 parsers, have also generalized and extended their work under the rubric of Zend.com&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;   &lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;The fourth quarter of 1998 initiated a period of explosive growth for PHP, as all open source technologies enjoyed massive publicity. In October 1998, according to the best guess, just over 100,000 unique domains used PHP in some way. Just over a year later, PHP broke the one-million domain mark. When we wrote the first edition of this book in the first half of 2000, the number had increased to about two million domains. As we write this, approximately 15 million public Web servers (in the software sense, not the hardware sense) have PHP installed on them.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Public PHP deployments run the gamut from mass-market sites such as Excite Webmail and the Indianapolis 500 Web site, which serve up millions of pageviews per day, through “massniche” sites such as Sourceforge.net and Epinions.com, which tend to have higher functionality needs and hundreds of thousands of users, to e-commerce and brochureware sites such as The Bookstore at Harvard.com and Sade.com (Web home of the British singer), which must be visually attractive and easy to update. There are also PHP-enabled parts of sites, such as the forums on the Internet Movie Database (imdb.com); and a large installed base of nonpublic PHP deployments, such as LDAP directories (MCI WorldCom built one with over 100,000 entries) and trouble-ticket tracking systems.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;In its newest incarnation, PHP5 strives to deliver something many users have been clamoring for over the past few years: much improved object-oriented programming (OOP) functionality. PHP has long nodded to the object programming model with functions that allow object programmers to pull out results and information in a way familiar to them. These efforts still fell short of the ideal for many programmers, however, and efforts to force PHP to build in fully object-oriented systems often yielded unintended results and hurt performance. PHP5’s newly rebuilt object model brings PHP more in line with other object-oriented languages such as Java and C++, offering support for features such as overloading, interfaces, private member variables and methods, and other standard OOP constructions.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;With the crash of the dot-com bubble, PHP is poised to be used on more sites than ever.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Demand for Web-delivered functionality has decreased very little, and emerging technological standards continue to pop up all the time, but available funding for hardware, licenses, and especially headcount has drastically decreased. In the post-crash Web world, PHP’s shallow learning curve, quick implementation of new functionality, and low cost of deployment are hard arguments to beat.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-7211909930889508997?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/7211909930889508997/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=7211909930889508997' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7211909930889508997'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7211909930889508997'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/05/history-of-php.html' title='The History of PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1999848361358966296</id><published>2008-05-08T20:42:00.002-03:00</published><updated>2008-05-08T20:45:06.979-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>What is PHP and MySQL</title><content type='html'>&lt;span style="font-weight: bold;"&gt;What Is PHP?&lt;/span&gt;  &lt;p style="margin-bottom: 0cm;"&gt;PHP is the Web development language written by and for Web developers. PHP stands for PHP: Hypertext Preprocessor. The product was originally named Personal Home Page Tools, and many people still think that’s what the acronym stands for. But as it expanded in scope, a new and more appropriate (albeit GNU-ishly recursive) name was selected by community vote. PHP is currently in its fifth major rewrite, called PHP5 or just plain PHP.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;PHP is a server-side scripting language, which can be embedded in HTML or used as a standalone binary (although the former use is much more common). Proprietary products in this niche are Microsoft’s Active Server Pages, Macromedia’s ColdFusion, and Sun’s Java Server Pages. Some tech journalists used to call PHP “the open source ASP” because its functionality is similar to that of the Microsoft product — although this formulation was misleading, as PHP was developed before ASP. Over the past few years, however, PHP and server-side Java have gained momentum, while ASP has lost mindshare, so this comparison no longer seems appropriate. You can think of it as a collection of super-HTML tags or small programs that run inside your Web pages — except on the server side, before they get sent to the browser. For example, you can use PHP to add common headers and footers to all the pages on a site or to store form-submitted data in a database.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Strictly speaking, PHP has little to do with layout, events, on the fly DOM  manipulation, or really anything about what a Web page looks and sounds like. In fact, most of what PHP does is invisible to the end user. Someone looking at a PHP page will not necessarily be able to tell that it was not written purely in HTML, because usually the result of PHP is HTML.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;PHP is an official module of Apache HTTP Server, the market-leading free Web server that runs about 67 percent of the World Wide Web (according to the widely quoted Netcraft Web server survey). This means that the PHP scripting engine can be built into the Web Server itself, leading to faster processing, more efficient memory allocation, and greatly simplified maintenance. Like Apache Server, PHP is fully cross-platform, meaning it runs native on sev-eral flavors of Unix, as well as on Windows and now on Mac OS X. All projects under the aegis of the Apache Software Foundation — ncluding PHP — are open source software.&lt;/p&gt;   &lt;p style="margin-bottom: 0cm; font-weight: bold;"&gt;What Is MySQL?&lt;/p&gt;  &lt;p style="margin-bottom: 0cm;"&gt;MySQL (pronounced My Ess Q El) is an open source, SQL Relational Database Management System (RDBMS) that is free for many uses (more detail on that later). Early in its history, MySQL occasionally faced opposition due to its lack of support for some core SQL constructs such as subselects and foreign keys. Ultimately, however, MySQL found a broad, enthusiastic user base for its liberal licensing terms, perky performance, and ease of use. Its acceptance was aided in part by the wide variety of other technologies such as PHP, Java, Perl, Python, and the like that have encouraged its use through stable, well-documented modules and extensions. MySQL has not failed to reward the loyalty of these users with the addition of both subselects and foreign keys as of the 4.1 series.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;Databases in general are useful, arguably the most consistently useful family of software products —the “killer product” of modern computing. Like many competing products, both free and commercial, MySQL isn’t a database until you give it some structure and form. You might think of this as the difference between a database and an RDBMS (that is, RDBMS plus user requirements equals a database).&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;There’s lots more to say about MySQL, but then again, there’s lots more space in which to say it.&lt;/p&gt; &lt;p style="margin-bottom: 0cm;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1999848361358966296?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1999848361358966296/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1999848361358966296' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1999848361358966296'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1999848361358966296'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/05/what-is-php-and-mysql.html' title='What is PHP and MySQL'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4529184889113671696</id><published>2008-04-25T19:39:00.002-03:00</published><updated>2008-04-25T19:40:15.345-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>What Is PHP?</title><content type='html'>PHP is an open-source, server-side, HTML-embedded Web-scripting language that is compatible with all the major Web servers (most notably Apache). PHP enables you to embed code fragments in normal HTML pages — code that is interpreted as your pages are served up to users. PHP also serves as a “glue” language, making it easy to connect your Web pages to server-side databases.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4529184889113671696?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4529184889113671696/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4529184889113671696' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4529184889113671696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4529184889113671696'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/04/what-is-php.html' title='What Is PHP?'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4248936381572080499</id><published>2008-04-07T09:50:00.000-03:00</published><updated>2008-07-02T09:54:39.176-03:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Operators'/><title type='text'>Php Comparison Operators</title><content type='html'>&lt;span style="font-size: 10pt; font-family: Arial;" lang="EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Comparison operators, as their name implies, allow you to compare two values. You may also be interested in viewing the type comparison tables, as they show examples of various type related comparisons. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;a name="id2539123"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Comparison Operators&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="" border="1" cellpadding="0"&gt;  &lt;thead&gt;   &lt;tr style=""&gt;    &lt;td style="padding: 0.75pt;"&gt;    &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Example&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;    &lt;/td&gt;    &lt;td style="padding: 0.75pt;"&gt;    &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Name&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;    &lt;/td&gt;    &lt;td style="padding: 0.75pt;"&gt;    &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Result&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;    &lt;/td&gt;   &lt;/tr&gt;  &lt;/thead&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a == $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Equal&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;   if $a is equal to $b.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a === $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Identical&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN-US"&gt;   if $a is equal to $b, and they are of the same type. &lt;/span&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;(introduced in PHP 4) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a != $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Not equal&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt; if $a is not equal to $b.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a &amp;lt;&amp;gt; $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Not equal&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt; if $a is not equal to $b.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a !== $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Not identical&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt; if $a is not equal to $b, or they are not of the same type.   (introduced in PHP 4) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a &amp;lt; $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Less than&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt; if $a is strictly less than $b.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a &amp;gt; $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Greater than&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt; if $a is strictly greater than $b.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a &amp;lt;= $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Less than or equal to &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt; if $a is less than or equal to $b.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;$a &amp;gt;= $b&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Greater than or equal to &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;TRUE&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt; if $a is greater than or equal to $b.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;If you compare an integer with a string, the string is converted to a number. If you compare two numerical strings, they are compared as integers. These rules also apply to the switch statement. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&amp;lt;?php&lt;br /&gt;var_dump(0 == "a"); // 0 == 0 -&amp;gt; true&lt;br /&gt;var_dump("1" == "01"); // 1 == 1 -&amp;gt; true&lt;br /&gt;var_dump("1" == "1e0"); // 1 == 1 -&amp;gt; true&lt;br /&gt;&lt;br /&gt;switch ("a") {&lt;br /&gt;case 0:&lt;br /&gt;    echo "0";&lt;br /&gt;    break;&lt;br /&gt;case "a": // never reached because "a" is already matched with 0&lt;br /&gt;    echo "a";&lt;br /&gt;    break;&lt;br /&gt;}&lt;br /&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;For various types, comparison is done according to the following table (in order). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;a name="language.operators.comparison.types"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Comparison with Various Types&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;table class="MsoNormalTable" style="" border="1" cellpadding="0"&gt;  &lt;thead&gt;   &lt;tr style=""&gt;    &lt;td style="padding: 0.75pt;"&gt;    &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Type of Operand 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;    &lt;/td&gt;    &lt;td style="padding: 0.75pt;"&gt;    &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Type of Operand 2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;    &lt;/td&gt;    &lt;td style="padding: 0.75pt;"&gt;    &lt;p class="MsoNormal" style="text-align: center;" align="center"&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Result&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;    &lt;/td&gt;   &lt;/tr&gt;  &lt;/thead&gt;  &lt;tbody&gt;&lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;null or string&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;String&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Convert &lt;b&gt;NULL&lt;/b&gt; to "", numerical or lexical comparison&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;bool or null&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;anything&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Convert to bool, FALSE &amp;lt; TRUE&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;object&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;object&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Built-in classes can define its own comparison, different   classes are uncomparable, same class - compare properties the same way as   arrays (PHP 4), PHP 5 has its own explanation&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.string.html"&gt;&lt;span style="color: black;"&gt;string&lt;/span&gt;&lt;/a&gt;, &lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.resource.html"&gt;&lt;span style="color: black;"&gt;resource&lt;/span&gt;&lt;/a&gt; or number&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.string.html"&gt;&lt;span style="color: black;"&gt;string&lt;/span&gt;&lt;/a&gt;, &lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.resource.html"&gt;&lt;span style="color: black;"&gt;resource&lt;/span&gt;&lt;/a&gt; or number&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Translate strings and resources to numbers, usual math&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.array.html"&gt;&lt;span style="color: black;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.array.html"&gt;&lt;span style="color: black;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;Array with fewer members is smaller, if key from operand 1 is   not found in operand 2 then arrays are uncomparable, otherwise - compare   value by value (see following example)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.array.html"&gt;&lt;span style="color: black;"&gt;array&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;anything&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.array.html"&gt;&lt;span style="color: black;"&gt;array&lt;/span&gt;&lt;/a&gt; is always greater&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt;  &lt;tr style=""&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.object.html"&gt;&lt;span style="color: black;"&gt;object&lt;/span&gt;&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;anything&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;   &lt;td style="padding: 0.75pt;"&gt;   &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;"&gt;&lt;a href="mk:@MSITStore:C:%5CDocuments%20and%20Settings%5CFabianPerez%5CEscritorio%5Cphp_manual_en.chm::/en/language.types.object.html"&gt;&lt;span style="color: black;"&gt;object&lt;/span&gt;&lt;/a&gt; is always greater&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;   &lt;/td&gt;  &lt;/tr&gt; &lt;/tbody&gt;&lt;/table&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;a name="id2539552"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Example Transcription of standard array comparison&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&amp;lt;?php&lt;br /&gt;// Arrays are compared like this with standard comparison operators&lt;br /&gt;function standard_array_compare($op1, $op2)&lt;br /&gt;{&lt;br /&gt;    if (count($op1) &amp;lt; count($op2)) {&lt;br /&gt;        return -1; // $op1 &amp;lt; $op2&lt;br /&gt;    } elseif (count($op1) &amp;gt; count($op2)) {&lt;br /&gt;        return 1; // $op1 &amp;gt; $op2&lt;br /&gt;    }&lt;br /&gt;    foreach ($op1 as $key =&amp;gt; $val) {&lt;br /&gt;        if (!array_key_exists($key, $op2)) {&lt;br /&gt;            return null; // uncomparable&lt;br /&gt;        } elseif ($val &amp;lt; $op2[$key]) {&lt;br /&gt;            return -1;&lt;br /&gt;        } elseif ($val &amp;gt; $op2[$key]) {&lt;br /&gt;            return 1;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    return 0; // $op1 == $op2&lt;br /&gt;}&lt;br /&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;a name="language.operators.comparison.ternary"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Ternary Operator&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Another conditional operator is the "?:" (or ternary) operator. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;a name="id2539612"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Example Assigning a default value&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&amp;lt;?php&lt;br /&gt;// Example usage for: Ternary Operator&lt;br /&gt;$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];&lt;br /&gt;&lt;br /&gt;// The above is identical to this if/else statement&lt;br /&gt;if (empty($_POST['action'])) {&lt;br /&gt;    $action = 'default';&lt;br /&gt;} else {&lt;br /&gt;    $action = $_POST['action'];&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;br /&gt;The expression &lt;i&gt;(expr1) ? (expr2) : (expr3)&lt;/i&gt; evaluates to &lt;i&gt;expr2&lt;/i&gt; if &lt;i&gt;expr1&lt;/i&gt; evaluates to &lt;b&gt;TRUE&lt;/b&gt;, and &lt;i&gt;expr3&lt;/i&gt; if &lt;i&gt;expr1&lt;/i&gt; evaluates to &lt;b&gt;FALSE&lt;/b&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Note: &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Please note that the ternary operator is a statement, and that it doesn't evaluate to a variable, but to the result of a statement. This is important to know if you want to return a variable by reference. The statement &lt;i&gt;return $var == 42 ? $a : $b;&lt;/i&gt; in a return-by-reference function will therefore not work and a warning is issued in later PHP versions. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Note: &lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Is is recommended that you avoid "stacking" ternary expressions. PHP's behaviour when using more than one ternary operator within a single statement is non-obvious: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal" style=""&gt;&lt;a name="id2539686"&gt;&lt;/a&gt;&lt;b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;Example Non-obvious Ternary Behaviour&lt;/span&gt;&lt;/b&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoNormal"&gt;&lt;span style="font-size: 10pt; font-family: Arial; color: black;" lang="EN"&gt;&amp;lt;?php&lt;br /&gt;// on first glance, the following appears to output 'true'&lt;br /&gt;echo (true?'true':false?'t':'f');&lt;br /&gt;&lt;br /&gt;// however, the actual output of the above is 't'&lt;br /&gt;// this is because ternary expressions are evaluated from left to right&lt;br /&gt;&lt;br /&gt;// the following is a more obvious version of the same code as above&lt;br /&gt;echo ((true ? 'true' : 'false') ? 't' : 'f');&lt;br /&gt;&lt;br /&gt;// here, you can see that the first expression is evaluated to 'true', which&lt;br /&gt;// in turn evaluates to (bool)true, thus returning the true branch of the&lt;br /&gt;// second ternary expression.&lt;br /&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4248936381572080499?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4248936381572080499/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4248936381572080499' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4248936381572080499'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4248936381572080499'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/04/php-comparison-operators.html' title='Php Comparison Operators'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-8558113094615131087</id><published>2008-02-17T19:47:00.000-02:00</published><updated>2008-02-17T19:48:19.809-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sintaxis'/><title type='text'>Como manejar archivos con Php</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Apertura de un archivo con PHP&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;La función utilizada para abrir un archivo en PHP es &lt;/span&gt;&lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;fopen&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;, la sintaxis.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;fp_handler=fopen(“path”,”modo”);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Path es la ruta completa del archivo a abrir, si el path comienza con “http://” se realiza una conexión a la URL indicada y se abre la página como si fuera un archivo (con las limitaciones lógicas, por ejemplo no es posible escribir).&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Los modos en los que se puede abrir un archivo son:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;r Sólo lectura&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;r+ Lectura y escritura&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;w Sólo escritura, si no existe el archivo lo crea, si existe lo trunca&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;w+ Lectura y escritura, si existe lo trunca, si no existe lo crea&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;a Modo append sólo escritura si no existe lo crea&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;a+ Modo append lectura y escritura si no existe lo crea&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;La función devuelve un file_handler que luego debe ser usado en todas las funciones de tipo fnombre_funcion, como por ejemplo fgets, fputs, fclose, fread, fwrite, etc.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Lectura desde un archivo con Php&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Las funciones que pueden usarse para leer un archivo son:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;string=fgets(file_handler, longitud)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; : Lee una línea de texto hasta el fin de línea o bien hasta que se cumpla la longitud indicada, devuelve el resultado en la variable pasada. El archivo debe estar abierto con fopen.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;var=fread(file_handler, cantidad)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;: Lee la cantidad de bytes indicados ignorando saltos de línea y deja el resultado en la variable var.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Ejemplo&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;$buffer=fread($fp, 1024);&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; //Lee 1Kb desde el archivo cuyo handler es $fp &lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;string=fgetss(file_handler, longitud)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Idéntica a fgets con la diferencia de que los tags html son eliminados del archivo a medida que se lee el mismo. Opcionalmente puede pasarse una lista de tags que no deben ser eliminados.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Ejemplo:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;$string=fgetss($fp,999999,”&amp;lt;b&amp;gt; &amp;lt;i&amp;gt; &amp;lt;table&amp;gt; &amp;lt;tr&amp;gt; &amp;lt;td&amp;gt;”);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Lee una línea (de cualquier longitud) eliminando los tags html excepto los indicados como segundo parámetro. Los tags que cierran los tags especificados en la lista de tags permitidos tampoco son eliminados.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Escritura a un archivo con Php&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;fwrite(file_handler, variable, longitud);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Escribe la variable al archivo indicado por file_handler. Si esta indicado el parámetro “longitud” (que es opcional) se escribirán tantos bytes como la longitud indicada por dicho parámetro o como la longitud de la variable, en aquellos casos en que el parámetro longitud es mayor que la longitud de la variable.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;La función devuelve la cantidad de bytes escritos en el archivo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Ejemplo:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;$q = fwrite($fp,$buffer,999999);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;fputs es idéntico a fwrite y funciona de la misma manera. (es un alias).&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Cierre de archivos con Php&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;fclose(file_handler)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Cierra un archivo abierto con fopen.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Fin de archivo con Php&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;boolean = feof(file_handler);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Devuelve verdadero si no quedan más bytes para leer en el archivo o si se produce algún tipo de error al leer.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Ejemplo:&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;$fp=fopen(“/usr/luis/archivo.txt”,”r”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;while(!feof($fp)) {&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;$s=fgets($fp,999999);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;print(“$s”);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Manejo de archivos con Php&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;PHP provee funciones para copiar, renombrar, mover y borrar archivos y directorios, las funciones son:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;rename(path_origen, path_destino)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;; Renombra un archivo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Ejemplo:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;$newname=”/usr/eduardo/file.txt”;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Rename(“/usr/eduardo/archivo.txt”,”$newname”);&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;unlink(path_a_borrar);&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Elimina un archivo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;rmdir(directorio_a_borrar);&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Elimina un directorio (debe estar vacío)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;mkdir(path_a_crear);&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Crea un directorio Nuevo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;copy(path_origen, path_destino);&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Copia un archivo o varios.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Otras funciones útiles con Php&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;fseek(file_handler,posicion,desde)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Posiciona el puntero de lectura/escritura de un archivo en el offset indicado. El parámetro “desde” es opcional y puede tomar uno de los siguientes valores:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;SEEK_SET (el offset es absoluto)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;SEEK_CUR (el offset es relativo a la posición actual)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;SEEK_END (el offset es desde el final del archivo)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;El default es SEEK_SET&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;ftruncate(file_handler, longitud)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Trunca el archivo indicado a la longitud en bytes especificada.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;array=file(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Lee un archivo de texto y devuelve un vector donde cada elemento del vector es una línea del archivo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;file_exists(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Devuelve true/false según el path indicado exista o&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;no.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;filemtime(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Devuelve la fecha de última modificación de un archivo en formato Unix. (ver manejo de fechas)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;filesize(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Devuelve el tamaño de un archivo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;filetype(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Devuelve el tipo de un archivo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;flock(file_handler,modo)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Lockea un archivo (independientemente del filesystem),&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;el modo puede ser:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;1: Lock en modo lectura (compartido)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;2: Lock en modo escritura (exclusivo)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;3: Release del lock adquirido.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Al hacer un fclose del archivo se liberan automáticamente los locks adquiridos sobre el mismo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Si flock no puede obtener el lock espera hasta que el lock este disponible, si se quiere que flock no bloquee el script sumar 4 al modo (modos: 5,6,7) y consultar por el valor devuelto por la función: true si el lock fue adquirido o false si no fue adquirido. Usando esta función pueden implementarse mecanismos de sincronización entre procesos.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;fpassthru(file_handler)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Escribe al standard_output el contenido del archivo.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;readfile(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Lee todo el archivo y lo escribe al standard output.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;is_dir(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; True/false según el path sea un directorio&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;is_file(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; True/false según el path sea un archivo&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;tempnam(path)&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt; Dado el nombre de un directorio devuelve un nombre de archivo que no existe en el directorio dado (útil para crear archivos temporarios)&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;Manejo de directorios con Php&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Las siguientes funciones de PHP están orientadas a recorrer directorios y obtener los archivos que se encuentran dentro de ellos. Las funciones son independientes del file-system con lo cual funcionan correctamente tanto en UNIX como en Windows.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;directory_handle = opendir(path);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Abre el directorio pasado como parámetro y devuelve un handler al directorio, previamente puede usarse la función is_dir(path) para verificar si el path es un directorio en caso de que esta validación sea necesaria.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;string = readdir(directory_handler)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Lee la próxima entrada en el directorio abierto con opendir, usualmente las dos primeras entradas de un directorio con “.” y “..” por lo que el código que procesa los archivos del directorio debe tener esto en cuenta para no procesar dichas entradas en caso de que tal cosa no sea deseable.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;closedir(directory_handler)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Cierra un handler abierto con opendir.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;rewinddir(directory_handler)&lt;/span&gt;&lt;br /&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;Rebobina el puntero interno de un directorio para que apunte nuevamente al comienzo del mismo.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-8558113094615131087?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/8558113094615131087/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=8558113094615131087' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/8558113094615131087'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/8558113094615131087'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/como-manejar-archivos-con-php.html' title='Como manejar archivos con Php'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-5993504460761671941</id><published>2008-02-17T19:46:00.000-02:00</published><updated>2008-02-17T19:47:17.547-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Estructuras de control'/><title type='text'>Estructuras de control en php: la estructura "if"</title><content type='html'>&lt;div style="text-align: justify;"&gt;El caso de la instruccion &lt;span style="font-weight: bold;"&gt;"IF"&lt;/span&gt; es una de las características más importantes de muchos idiomas, incluido PHP. Permite la ejecución condicional de fragmentos de código. PHP cuenta con una estructura que es similar a la de C:&lt;/div&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;if (expr)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;statement&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText" face="arial" style="text-align: justify;"&gt;La expresión se evalúa a su valor Boolean. Si la expresión evalúa a TRUE, PHP ejecutará las instrucciones, y si se evalúa a FALSE la ignora.&lt;/p&gt;&lt;p class="MsoPlainText" style="text-align: justify; font-family: arial;"&gt;El siguiente &lt;span style="font-weight: bold;"&gt;ejemplo&lt;/span&gt; se mostrará que "a es mayor que b" si $ a es mayor que $ b:&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;if ($a &amp;gt; $b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;echo "a is bigger than b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="text-align: justify;font-family:arial;" align="justify"&gt;&lt;span lang="EN-US"&gt;A menudo, lo que se quiere es tener más de una declaración para ser ejecutado condicionalmente. Por supuesto, no hay necesidad de envolver cada declaración con una cláusula IF. En lugar de ello, podemos agrupar varias sentencias. Por ejemplo, este código mostrará "a es mayor que b" si $ a es mayor que $ b, y luego asignar el valor de $ a a $ b:&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="text-align: justify;font-family:arial;" align="justify"&gt;&lt;span lang="EN-US"&gt;&lt;strong&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;if ($a &amp;gt; $b) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;echo "a is bigger than b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;$b = $a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-weight: bold;font-family:arial;"&gt;&lt;span lang="EN-US"&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText" style="text-align: justify;font-family:arial;" &gt;&lt;span lang="EN-US"&gt;La declaracion IF se pueden anidar indefinidamente en el marco de otras estructuras de control, que le proporciona una total flexibilidad para la ejecución condicional de las diferentes partes de tu programa.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-5993504460761671941?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/5993504460761671941/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=5993504460761671941' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/5993504460761671941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/5993504460761671941'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/estructuras-de-control-en-php-la.html' title='Estructuras de control en php: la estructura &quot;if&quot;'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4401696593434469801</id><published>2008-02-17T19:45:00.000-02:00</published><updated>2008-02-17T19:46:09.538-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Estructuras de control'/><title type='text'>Estructuras de Control en PHP: elseif</title><content type='html'>&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-weight: bold;"&gt;elseif&lt;/span&gt;, como su nombre sugiere, es una &lt;span style="font-weight: bold;"&gt;combinación de if y else&lt;/span&gt;. Como else, extiende una sentencia if para ejecutar una sentencia diferente en caso de que la expresión if original se evalúa como &lt;span style="font-weight: bold;"&gt;FALSE&lt;/span&gt;. No obstante, a diferencia de else, ejecutará esa expresión alternativa solamente si la expresión condicional elseif se evalúa como &lt;span style="font-weight: bold;"&gt;TRUE&lt;/span&gt;. Por ejemplo, el siguiente código mostraría a es mayor que b, a es igual a b o a es menor que b:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;  &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;pre&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt; &lt;/span&gt;if ($a &amp;gt; $b) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;     &lt;/span&gt;&lt;/span&gt;print "a es mayor que b";&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt; &lt;/span&gt;} elseif ($a == $b) {&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;     &lt;/span&gt;print "a es igual que b";&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt; &lt;/span&gt;} else {&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;     &lt;/span&gt;print "a es mayor que b";&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt; &lt;/span&gt;}&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;/pre&gt;&lt;br /&gt;&lt;div style="text-align: justify;"&gt;Puede haber varios elseifs dentro de la misma sentencia if. La primera expresión elseif (si hay alguna) que se evalúe como TRUE se ejecutaría. En PHP, también se puede escribir 'else if' (con dos palabras) y el comportamiento sería idéntico al de un 'elseif' (una sola palabra). El significado sintáctico es ligeramente distinto (si estas familiarizado con C, es el mismo comportamiento) pero la línea básica es que ambos resultarían tener exactamente el mismo comportamiento.&lt;/div&gt;&lt;div&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;La sentencia elseif se ejecuta sólo si la expresión if precedente y cualquier expresión elseif precedente se evalúan como FALSE, y la expresión elseif actual se evalúa como TRUE.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4401696593434469801?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4401696593434469801/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4401696593434469801' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4401696593434469801'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4401696593434469801'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/estructuras-de-control-en-php-elseif.html' title='Estructuras de Control en PHP: elseif'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-3218978684726143551</id><published>2008-02-17T19:44:00.000-02:00</published><updated>2008-02-17T19:45:08.038-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Variables'/><title type='text'>Variables variables en PHP</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;A veces es conveniente tener nombres de variables variables. Dicho de otro modo, son nombres de variables que se pueden establecer y usar dinámicamente. Una variable normal se establece con una sentencia como:&lt;/span&gt;&lt;/span&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$a = "hello";&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;Una variable variable toma el valor de una variable y lo trata como el nombre de una variable. En el ejemplo anterior, hello, se puede usar como el nombre de una variable utilizando dos signos $. p.ej.&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$$a = "world";&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;En este momento se han definido y almacenado dos variables en el árbol de símbolos de PHP: $a, que contiene "hello", y $hello, que contiene "world". Es más, esta sentencia:&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;echo "$a ${$a}";&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;produce el mismo resultado que:&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;echo "$a $hello";&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;p.ej. ambas producen el resultado: hello world.&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;Para usar variables variables con matrices, hay que resolver un problema de ambigüedad. Si se escribe $$a[1] el intérprete necesita saber si nos referimos a utilizar $a[1] como una variable, o si se pretendía utilizar $$a como variable y el índice [1] como índice de dicha variable. La sintaxis para resolver esta ambigüedad es: ${$a[1]} para el primer caso y ${$a}[1] para el segundo.&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p style="font-family: arial;"&gt;&lt;/o:p&gt;&lt;span style="font-family:arial;"&gt;Tener en cuenta que variables variables no pueden usarse con Matrices superglobales. Esto significa que no se pueden hacer cosas como ${$_GET}. &lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-3218978684726143551?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/3218978684726143551/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=3218978684726143551' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3218978684726143551'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3218978684726143551'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/variables-variables-en-php.html' title='Variables variables en PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4481922500193014281</id><published>2008-02-17T19:42:00.000-02:00</published><updated>2008-02-17T19:43:59.442-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sintaxis'/><title type='text'>Qué es PHP?</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:arial;"&gt;PHP (acrónimo de "PHP: Hypertext Preprocessor") es un lenguaje de "código abierto" interpretado, de alto nivel, embebido en páginas HTML y ejecutado en el servidor. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;    &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Una respuesta corta y concisa, pero, ¿qué significa realmente? Un ejemplo nos aclarará las cosas: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;pre&gt; &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;html&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;head&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&amp;lt;title&amp;gt;Ejemplo&amp;lt;/title&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;/head&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;body&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&amp;lt;?php &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;echo "Hola, soy un script PHP!"; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;/body&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;/html&amp;gt;  &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;/pre&gt;  &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Puede apreciarse que no es lo mismo que un script escrito en otro lenguaje de programación como Perl o C -- En vez de escribir un programa con muchos comandos para crear una salida en HTML, escribimos el código HTML con cierto código PHP embebido (incluido) en el mismo, que producirá cierta salida (en nuestro ejemplo, producirá un texto). El código PHP se incluye entre etiquetas especiales de comienzo y final que nos permitirán entrar y salir del modo PHP. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Lo que distingue a PHP de la tecnología Javascript, la cual se ejecuta en la máquina cliente, es que el código PHP es ejecutado en el servidor. Si tuviésemos un script similar al de nuestro ejemplo en nuestro servidor, el cliente solamente recibiría el resultado de su ejecución en el servidor, sin ninguna posibilidad de determinar qué código ha producido el resultado recibido. El servidor web puede ser incluso configurado para que procese todos los archivos HTML con PHP. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoPlainText"  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Lo mejor de usar PHP es que es extremadamente simple para el principiante, pero a su vez, ofrece muchas características avanzadas para los programadores profesionales.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4481922500193014281?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4481922500193014281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4481922500193014281' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4481922500193014281'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4481922500193014281'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/qu-es-php.html' title='Qué es PHP?'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1653666992209237820</id><published>2008-02-17T19:37:00.002-02:00</published><updated>2008-02-17T19:38:43.542-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sintaxis'/><title type='text'>Que se puede hacer con PHP?</title><content type='html'>&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;PHP puede hacer cualquier cosa que se pueda hacer con un script CGI, como procesar la información de formularios, generar páginas con contenidos dinámicos, o enviar y recibir cookies. Y esto no es todo, se puede hacer mucho más. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Existen tres campos en los que se usan scripts escritos en PHP. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;Scripts del lado del servidor.&lt;/span&gt; Este es el campo más tradicional y el principal foco de trabajo. Se necesitan tres cosas para que esto funcione. El intérprete PHP (CGI ó módulo), un servidor web y un navegador. Es necesario correr el servidor web con PHP instalado. El resultado del programa PHP se puede obtener a través del navegador, conectándose con el servidor web. Consultar la sección Instrucciones de instalación para más información.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;Scripts en la línea de comandos.&lt;/span&gt; Puede crear un script PHP y correrlo sin ningún servidor web o navegador. Solamente necesita el intérprete PHP para usarlo de esta manera. Este tipo de uso es ideal para scripts ejecutados regularmente desde cron (en *nix o Linux) o el Planificador de tareas (en Windows). Estos scripts también pueden ser usados para tareas simples de procesamiento de texto.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-weight: bold;"&gt;Escribir aplicaciones de interfaz gráfica.&lt;/span&gt; Probablemente PHP no sea el lenguaje más apropiado para escribir aplicaciones gráficas, pero si conoce bien PHP, y quisiera utilizar algunas características avanzadas en programas clientes, puede utilizar PHP-GTK para escribir dichos programas. También es posible escribir aplicaciones independientes de una plataforma. PHP-GTK es una extensión de PHP, no disponible en la distribución principal.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;PHP puede ser utilizado en cualquiera de los principales sistemas operativos del mercado, incluyendo Linux, muchas variantes Unix (incluyendo HP-UX, Solaris y OpenBSD), Microsoft Windows, Mac OS X, RISC OS y probablemente alguno más. PHP soporta la mayoría de servidores web de hoy en día, incluyendo Apache, Microsoft Internet Information Server, Personal Web Server, Netscape e iPlanet, Oreilly Website Pro server, Caudium, Xitami, OmniHTTPd y muchos otros. PHP tiene módulos disponibles para la mayoría de los servidores, para aquellos otros que soporten el estándar CGI, PHP puede usarse como procesador CGI. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;De modo que, con PHP tiene la libertad de elegir el sistema operativo y el servidor de su gusto. También tiene la posibilidad de usar programación procedimental o programación orientada a objetos. Aunque no todas las características estándar de la programación orientada a objetos están implementadas en la versión actual de PHP, muchas bibliotecas y aplicaciones grandes (incluyendo la biblioteca PEAR) están escritas íntegramente usando programación orientada a objetos. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Con PHP no se encuentra limitado a resultados en HTML. Entre las habilidades de PHP se incluyen: creación de imágenes, archivos PDF y películas Flash (usando libswf y Ming) sobre la marcha. Tambié puede presentar otros resultados, como XHTM y archivos XML. PHP puede autogenerar éstos archivos y almacenarlos en el sistema de archivos en vez de presentarlos en la pantalla. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Quizás la característica más potente y destacable de PHP es su soporte para una gran cantidad de bases de datos. Escribir un interfaz vía web para una base de datos es una tarea simple con PHP. Las siguientes bases de datos están soportadas actualmente: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;ul style="text-align: justify;"&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Adabas D&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Ingres&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Oracle (OCI7 and OCI8) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;dBase&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;InterBase&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Ovrimos &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Empress&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;FrontBase&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;PostgreSQL &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;FilePro (read-only)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;mSQL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Solid &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Hyperwave&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Direct MS-SQL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Sybase &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;IBM DB2&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;MySQL&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Velocis &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Informix&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;ODBC&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Unix dbm &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div style="text-align: justify;"&gt;                                            &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;También contamos con una extensión DBX de abstracción de base de datos que permite usar de forma transparente cualquier base de datos soportada por la extensión. Adicionalmente, PHP soporta ODBC (el Estándar Abierto de Conexión con Bases de Datos), asi que puede conectarse a cualquier base de datos que soporte tal estándar. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;PHP también cuenta con soporte para comunicarse con otros servicios usando protocolos tales como LDAP, IMAP, SNMP, NNTP, POP3, HTTP, COM (en Windows) y muchos otros. También se pueden crear sockets puros. PHP soporta WDDX para el intercambio de datos entre lenguajes de programación en web. Y hablando de interconexión, PHP puede utilizar objetos Java de forma transparente como objetos PHP Y la extensión de CORBA puede ser utilizada para acceder a objetos remotos. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;PHP tiene unas características muy útiles para el procesamiento de texto, desde expresiones regulares POSIX extendidas o tipo Perl hasta procesadores de documentos XML. Para procesar y acceder a documentos XML, soportamos los estándares SAX y DOM. Puede utilizar la extensión XSLT para transformar documentos XML. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Si usa PHP en el campo del comercio electrónico, encontrará muy útiles las funciones Cybercash, CyberMUT, VeriSign Payflow Pro y CCVS para sus programas de pago. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;        &lt;/div&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style="font-size:100%;"&gt;Para terminar, contamos con muchas otras extensiones muy interesantes, las funciones del motor de búsquedas mnoGoSearch, funciones para pasarelas de IRC, utilidades de compresión (gzip, bz2),, conversión de calendarios, traducción, etc.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1653666992209237820?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1653666992209237820/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1653666992209237820' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1653666992209237820'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1653666992209237820'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/que-se-puede-hacer-con-php.html' title='Que se puede hacer con PHP?'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4704501138832399976</id><published>2008-02-17T19:37:00.001-02:00</published><updated>2008-02-17T19:37:28.903-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programacion script'/><title type='text'>Como saber que navegador usa un visitante con PHP</title><content type='html'>&lt;span style=";font-family:arial;font-size:100%;"  &gt;Para hacerlo, vamos a consultar la información que el navegador nos envía como parte de su petición HTTP. Esta información es guardada en una variable. Las variables siempre comienzan con un signo de dólar ("$") en PHP. La variable que vamos a utilizar en esta situación es &lt;/span&gt;&lt;span style="font-weight: bold;font-family:arial;font-size:100%;"  &gt;$_SERVER["HTTP_USER_AGENT"]&lt;/span&gt;&lt;span style=";font-family:arial;font-size:100%;"  &gt;.     &lt;/span&gt;&lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;$_SERVER&lt;/span&gt;&lt;span style="font-size:100%;"&gt; es una variable reservada por PHP que contiene toda la información del servidor web. Es conocida como Autoglobal (o Superglobal).&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Para poder ver esta variable solo necesitamos el siguiente codigo: &lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style="font-weight: bold;"&gt;&amp;lt;?php echo $_SERVER["HTTP_USER_AGENT"]; ?&amp;gt;&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;esto nos dara un resultado similar a: &lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style="font-weight: bold;"&gt;Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;$_SERVER es simplemente una variable que se encuentra disponible automáticamente en PHP. &lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Por ejemplo, si quisiéramos detectar el uso de "Internet Explorer", haríamos algo así: &lt;/span&gt;&lt;/p&gt; &lt;pre  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;   &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;if (strstr($_SERVER["HTTP_USER_AGENT"], "MSIE")) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;echo "Está usando Internet Explorer&amp;lt;br /&amp;gt;";&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;}  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt; &lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;/pre&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;esto nos dara un resultado similar a:&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style="font-weight: bold;"&gt;Esta usando Internet Explorer&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style=";font-family:arial;font-size:100%;"  lang="EN-US" &gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;En el caso anterior estamos buscando &lt;/span&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;"MSIE"&lt;/span&gt;&lt;span style="font-size:100%;"&gt; dentro de &lt;/span&gt;&lt;span style="font-weight: bold;font-size:100%;" &gt;$_SERVER["HTTP_USER_AGENT"]&lt;/span&gt;&lt;span style="font-size:100%;"&gt;. Si la cadena fue encontrada, la función devolverá verdadero ("TRUE"), la declaración "if" se evalúa a verdadero ("TRUE") y el código adentro de las llaves {} es ejecutado. De otra manera no resulta ejecutado. &lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4704501138832399976?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4704501138832399976/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4704501138832399976' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4704501138832399976'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4704501138832399976'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/como-saber-que-navegador-usa-un.html' title='Como saber que navegador usa un visitante con PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-6906417426879552334</id><published>2008-02-17T19:35:00.002-02:00</published><updated>2008-02-17T19:36:37.423-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='programacion script'/><title type='text'>Contador de usuarios activos con PHP</title><content type='html'>&lt;span style="font-size:100%;"&gt;Con este script podemos contar los usuarios activos con PHP.&lt;/span&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;No vamos a usar ninguna base de datos. En su lugar usaremos un archivo llamado usuarios.dat&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Creamos nuestro script PHP y lo llamamos activos.php&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;$tiempo_logout = 600; // segundos tras los cuales un usuario es marcado como inactivo&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;$arr = file("usuarios.dat");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;$contenido = $REMOTE_ADDR.":".time()." ";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;for ( $i = 0 ; $i &amp;lt; sizeof($arr) ; $i++ )&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;$tmp = explode(":",$arr[$i]);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;if (( $tmp[0] != $REMOTE_ADDR ) &amp;amp;&amp;amp; (( time() - $tmp[1] ) &amp;lt; $tiempo_logout ))&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;{&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;$contenido .= &lt;span style="" lang="EN-US"&gt;$REMOTE_ADDR.":".time()." ";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;$fp = fopen("usuarios.dat","w");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;fputs($fp,$contenido);&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;fclose($fp);&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;$array = file("usuarios.dat");&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;$USUARIOS_ACTIVOS = count($array);&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt;&lt;/span&gt;&lt;/p&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;La explicación de lo que hace el codigo anterior es la siguiente:&lt;/span&gt;&lt;/p&gt;    &lt;ul&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt; Cargamos usuarios.dat a un array&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;ul&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt; Creamos el archivo de texto con las IP y la hora de visita de los que visitan nuestra web&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;ul&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt; “Borramos” de ese archivo los que llevan más de $tiempo_logout sin actividad&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;ul&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt; Escribimos el archivo&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;  &lt;ul&gt;&lt;li&gt;&lt;span style="font-size:100%;"&gt; Declaramos una variable $USUARIOS_ACTIVOS que contiene el número de usuarios activos del momento&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;    &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;Para utilizar este Script, al principio de cualquier página ponemos&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt; &lt;/span&gt;&amp;lt;?php&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;      &lt;/span&gt;include(”activos.php”)&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt; &lt;/span&gt;?&amp;gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;y donde queremos mostrar el número de usuarios, usamos la variable $USUARIOS_ACTIVOS.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-6906417426879552334?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/6906417426879552334/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=6906417426879552334' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/6906417426879552334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/6906417426879552334'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/contador-de-usuarios-activos-con-php.html' title='Contador de usuarios activos con PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4869645129026677378</id><published>2008-02-17T19:35:00.001-02:00</published><updated>2008-02-17T19:35:36.858-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sintaxis'/><title type='text'>Como poner comentarios en el codigo Php</title><content type='html'>&lt;span style="font-family:Arial;"&gt;PHP soporta el estilo de comentarios de 'C', 'C++' y de la interfaz de comandos de Unix. &lt;/span&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Por ejemplo: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt; &lt;pre&gt; &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "Esto es una prueba"; // Esto es un comentario de una linea al estilo c++&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;/* Esta es una linea de un comentario multilíneas&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;       &lt;/span&gt;Esto es otra linea de un comentario multilinea */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "Esto es otra prueba";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "Y esto otra prueba mas"; # comentario tipo shell de unix&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;/pre&gt;   &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;Ejemplo:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;pre&gt;   &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;&amp;lt;h1&amp;gt;Esto es un &amp;lt;?php # echo "simple";?&amp;gt; ejemplo.&amp;lt;/h1&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Arial;"&gt;&amp;lt;p&amp;gt;El encabezado de arriba dice 'Esto es un simple ejemplo'. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/pre&gt; &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;Hay que tener cuidado con no anidar comentarios de estilo 'C', algo que puede ocurrir al comentar bloques largos de código. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;pre&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt; &lt;/span&gt;/*&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "esto es una prueba"; /* Este comentario puede causar problemas */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt; &lt;/span&gt;*/&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;/pre&gt; &lt;span style="font-family:Arial;"&gt;Los estilos de comentarios de una linea comentan hasta el final de la linea o del bloque actual de código PHP, lo primero que ocurra. Esto implica que el código HTML tras // ?&amp;gt; será impreso: ?&amp;gt; sale del modo PHP, retornando al modo HTML, el comentario // no le influye.&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4869645129026677378?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4869645129026677378/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4869645129026677378' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4869645129026677378'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4869645129026677378'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/como-poner-comentarios-en-el-codigo-php.html' title='Como poner comentarios en el codigo Php'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1794668448988713741</id><published>2008-02-17T19:34:00.001-02:00</published><updated>2008-02-17T19:34:55.992-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sintaxis'/><title type='text'>Formas de Entrar y salir de PHP</title><content type='html'>&lt;span style="font-family:Arial;"&gt;Para interpretar un archivo, php símplemente interpreta el texto del archivo hasta que encuentra uno de los carácteres especiales que delimitan el inicio de código PHP. El intérprete ejecuta entonces todo el código que encuentra, hasta que encuentra una etiqueta de fin de código, que le dice al intérprete que siga ignorando el código siguiente. Este mecanismo permite embeber código PHP dentro de HTML: todo lo que está fuera de las etiquetas PHP se deja tal como está, mientras que el resto se interpreta como código. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;Hay cuatro conjuntos de etiquetas que pueden ser usadas para denotar bloques de código PHP. De estas cuatro, sólo 2 (&amp;lt;?php. . .?&amp;gt; y &amp;lt;script language="php"&amp;gt;. . .&amp;lt;/script&amp;gt;) están siempre disponibles; el resto pueden ser configuradas en el fichero de php.ini para ser o no aceptadas por el intérprete. Mientras que el formato corto de etiquetas (short-form tags) y el estilo ASP (ASP-style tags) pueden ser convenientes, no son portables como la versión de formato largo de etiquetas. Además, si se pretende embeber código PHP en XML o XHTML, será obligatorio el uso del formato &amp;lt;?php. . .?&amp;gt; para la compatibilidad con XML. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;Las etiquetas soportadas por PHP son: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;Ejemplo: Formas de escapar de HTML&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;1.&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;?php echo("si quieres servir documentos XHTML o XML, haz como aquí\n"); ?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;2.&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;? echo ("esta es la más simple, una instrucción de procesado SGML \n"); ?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;?= expression ?&amp;gt; Esto es una abreviatura de "&amp;lt;? echo expression ?&amp;gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;3.&lt;span style=""&gt;  &lt;/span&gt;&lt;/span&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&amp;lt;script language="php"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;        &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;echo ("muchos editores (como FrontPage) no&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;              &lt;/span&gt;aceptan instrucciones de procesado");&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;/script&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;4.&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;% echo ("Opcionalmente, puedes usar las etiquetas ASP"); %&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;%= $variable; # Esto es una abreviatura de "&amp;lt;% echo . . ." %&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;El método primero, &amp;lt;?php. . .?&amp;gt;, es el más conveniente, ya que permite el uso de PHP en código XML como XHTML. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;El método segundo no siempre está disponible. El formato corto de etiquetas está disponible con la función short_tags() (sólo PHP 3), activando el parámetro del fichero de configuración de PHP short_open_tag, o compilando PHP con la opción --enable-short-tags del comando configure. Aunque esté activa por defecto en php.ini-dist, se desaconseja el uso del formato de etiquetas corto. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;El método cuarto sólo está disponible si se han activado las etiquetas ASP en el fichero de configuración: asp_tags. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;nota: El soporte de etiquetas ASP se añadió en la versión 3.0.4.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;nota: No se debe usar el formato corto de etiquetas cuando se desarrollen aplicaciones o bibliotecas con intención de redistribuirlas, o cuando se desarrolle para servidores que no están bajo nuestro control, porque puede ser que el formato corto de etiquetas no esté soportado en el servidor. Para generar código portable y redistribuíble, asegúrate de no usar el formato corto de etiquetas. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;La etiqueta de fin de bloque incluirá tras ella la siguiente línea si hay alguna presente. Además, la etiqueta de fin de bloque lleva implícito el punto y coma; no necesitas por lo tanto añadir el punto y coma final de la última línea del bloque PHP. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;PHP permite estructurar bloques como: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;Ejemplo: Métodos avanzados de escape&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;if ($expression) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;strong&amp;gt;This is true.&amp;lt;/strong&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;} else {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;strong&amp;gt;This is false.&amp;lt;/strong&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family:Arial;"&gt;Este ejemplo realiza lo esperado, ya que cuando PHP encuentra las etiquetas ?&amp;gt; de fin de bloque, empieza a escribir lo que encuentra tal cual hasta que encuentra otra etiqueta de inicio de bloque. El ejemplo anterior es, por supuesto, inventado. Para escribir bloques grandes de texto generamente es más eficiente separalos del código PHP que enviar todo el texto mediante las funciones echo(), print() o similares.&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1794668448988713741?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1794668448988713741/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1794668448988713741' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1794668448988713741'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1794668448988713741'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/formas-de-entrar-y-salir-de-php.html' title='Formas de Entrar y salir de PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-7045184052737579834</id><published>2008-02-17T19:33:00.000-02:00</published><updated>2008-02-17T19:34:10.514-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sintaxis'/><title type='text'>Uso de Formularios en PHP</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Otra de las características de PHP es que gestiona formularios de HTML. El concepto básico que es importante entender es que cualquier elemento de los formularios estará disponible automáticamente en su código PHP. Observemos un ejemplo: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Ejemplo: Un formulario HTML sencillo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&amp;lt;form action="accion.php" method="POST"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt; &lt;/span&gt;Su nombre: &amp;lt;input type="text" name="nombre" /&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt; &lt;/span&gt;Su edad: &amp;lt;input type="text" name="edad" /&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt; &lt;/span&gt;&amp;lt;input type="submit"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;&amp;lt;/form&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;No hay nada especial en este formularo, es HTML limpio sin ninguna clase de etiquetas desconocidas. Cuando el cliente llena éste formulario y oprime el botón etiquetado "Submit", una página titulada accion.php es llamada. En este archivo encontrará algo así: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Ejemplo: Procesamiento de información de nuestro formulario HTML&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Hola &amp;lt;?php echo $_POST["nombre"]; ?&amp;gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Tiene &amp;lt;?php echo $_POST["edad"]; ?&amp;gt; años &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Un ejemplo del resultado de este script podría ser: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Hola José.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Tiene 22 años&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;Es aparentemente obvio lo que hace. No hay mucho más que decir al respecto. Las variables $_POST["nombre"] y $_POST["edad"] son definidas automáticamente por PHP. Hace un momento usamos la variable autoglobal $_SERVER, ahora hemos introducido autoglobal $_POST, que contiene toda la información enviada por el método POST. Fíjese en el atributo method en nuestro formulario; es POST. Si hubiéramos usado GET, entonces nuestra información estaría en la variable autoglobal $_GET. También puede utilizar la autoglobal $_REQUEST si no le importa el origen de la petición. Ésta variable contiene una mezcla de información GET, POST y COOKIE.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-7045184052737579834?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/7045184052737579834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=7045184052737579834' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7045184052737579834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7045184052737579834'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/uso-de-formularios-en-php.html' title='Uso de Formularios en PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-2477974324773742788</id><published>2008-02-17T19:31:00.000-02:00</published><updated>2008-02-17T19:32:39.614-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Sintaxis'/><title type='text'>Separación de instrucciones en PHP</title><content type='html'>&lt;span style="font-family: arial;font-size:100%;" &gt;Las separación de instrucciones se hace de la misma manera que en C o Perl - terminando cada declaración con un punto y coma. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;p style="font-family: arial;font-family:arial;"  class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;La etiqueta de fin de bloque (?&amp;gt;) implica el fin de la declaración, por lo tanto lo siguiente es equivalente: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="font-family: arial;font-family:arial;"  class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;font-family:arial;"  class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "This is a test";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;font-family:arial;"  class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family: arial;font-size:100%;" &gt;&lt;span style=";font-size:12;" lang="EN-US" &gt;&amp;lt;&lt;/span&gt;&lt;span style=";font-size:10;" lang="EN-US" &gt;?php echo "This is a test" ?&lt;/span&gt;&lt;span style=";font-size:12;" lang="EN-US" &gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-2477974324773742788?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/2477974324773742788/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=2477974324773742788' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2477974324773742788'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2477974324773742788'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/separacin-de-instrucciones-en-php.html' title='Separación de instrucciones en PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4861205981470680931</id><published>2008-02-17T19:30:00.000-02:00</published><updated>2008-02-17T19:31:00.376-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tipo de datos'/><title type='text'>Tipos de datos en Php</title><content type='html'>PHP soporta ocho tipos primitivos.&lt;br /&gt;&lt;br /&gt;Cuatro tipos escalares:&lt;br /&gt;•    boolean&lt;br /&gt;•    integer&lt;br /&gt;•    float (número de punto-flotante, también conocido como 'double')&lt;br /&gt;•    string&lt;br /&gt;&lt;br /&gt;Dos tipos compuestos:&lt;br /&gt;•    array&lt;br /&gt;•    object&lt;br /&gt;&lt;br /&gt;Y finalmente dos tipos especiales:&lt;br /&gt;•    resource&lt;br /&gt;•    NULL&lt;br /&gt;&lt;br /&gt;También algunos pseudo-tipos por razones de legibilidad:&lt;br /&gt;•    mixed&lt;br /&gt;•    number&lt;br /&gt;•    callback&lt;br /&gt;&lt;br /&gt;Y la pseudo-variable $....&lt;br /&gt;&lt;br /&gt;También puede encontrar algunas referencias al tipo "double". Considere al tipo double como el mismo que float, los dos nombres existen solo por razones históricas.&lt;br /&gt;&lt;br /&gt;El tipo de una variable usualmente no es declarado por el programador; en cambio, es decidido en tiempo de compilación por PHP dependiendo del contexto en el que es usado la variable.&lt;br /&gt;nota: Si desea chequear el tipo y valor de una cierta expresión, use var_dump().&lt;br /&gt;Si tan solo desea una representación legible para humanos del tipo para propósitos de depuración, use gettype(). Para chequear por un cierto tipo, no use gettype(); en su lugar utilice las funciones is_tipo. Algunos ejemplos:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$un_bool = TRUE;   // un valor booleano&lt;br /&gt;$un_str  = "foo";  // una cadena&lt;br /&gt;$un_str2 = 'foo';  // una cadena&lt;br /&gt;$un_int  = 12;     // un entero&lt;br /&gt;&lt;br /&gt;echo gettype($un_bool); // imprime: boolean&lt;br /&gt;echo gettype($un_str);  // imprime: string&lt;br /&gt;&lt;br /&gt;// Si este valor es un entero, incrementarlo en cuatro&lt;br /&gt;if (is_int($un_int)) {&lt;br /&gt;   $un_int += 4;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Si $bool es una cadena, imprimirla&lt;br /&gt;// (no imprime nada)&lt;br /&gt;if (is_string($un_bool)) {&lt;br /&gt;   echo "Cadena: $un_bool";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Si quisiera forzar la conversión de una variable a cierto tipo, puede moldear la variable, o usar la función settype() sobre ella.&lt;br /&gt;Note que una variable puede ser evaluada con valores diferentes en ciertas situaciones, dependiendo del tipo que posee en cada momento.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4861205981470680931?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4861205981470680931/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4861205981470680931' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4861205981470680931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4861205981470680931'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/tipos-de-datos-en-php.html' title='Tipos de datos en Php'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-8165479372373760271</id><published>2008-02-17T19:29:00.000-02:00</published><updated>2008-02-17T19:30:15.140-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tipo de datos'/><title type='text'>Tipo de datos Booleanos en Php</title><content type='html'>Este es el tipo más simple. Un boolean expresa un valor de verdad. Puede ser TRUE or FALSE.&lt;br /&gt;nota: El tipo booleano fue introducido en PHP 4.&lt;br /&gt;&lt;br /&gt;Sintaxis:&lt;br /&gt;Para especificar un literal booleano, use alguna de las palabras clave TRUE o FALSE. Ambas son insensibles a mayúsculas y minúsculas.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$foo = True; // asignar el valor TRUE a $foo&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Usualmente se usa algún tipo de operador que deuelve un valor boolean, y luego éste es pasado a una estructura de control.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;// == es un operador que prueba por&lt;br /&gt;// igualdad y devuelve un booleano&lt;br /&gt;if ($accion == "mostrar_version") {&lt;br /&gt;   echo "La versión es 1.23";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// esto no es necesario...&lt;br /&gt;if ($mostrar_separadores == TRUE) {&lt;br /&gt;   echo "&amp;lt;hr&amp;gt;\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// ...porque se puede escribir simplemente&lt;br /&gt;if ($mostrar_separadores) {&lt;br /&gt;   echo "&amp;lt;hr&amp;gt;\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Conversión a booleano&lt;br /&gt;&lt;br /&gt;Para convertir explícitamente un valor a boolean, use el moldeamiento (bool) o (boolean). Sin embargo, en la mayoría de casos no es necesario usar el moldeamiento, ya que un valor será convertido automáticamente si un operador, función o estructura de control requiere un argumento tipo boolean.&lt;br /&gt;&lt;br /&gt;Cuando se realizan conversiones a boolean, los siguientes valores son considerados FALSE:&lt;br /&gt;&lt;br /&gt;•    el boolean FALSE mismo&lt;br /&gt;•    el integer 0 (cero)&lt;br /&gt;•    el float 0.0 (cero)&lt;br /&gt;•    el valor string vacío, y el string "0"&lt;br /&gt;•    un array con cero elementos&lt;br /&gt;•    un object con cero variables miembro (sólo en PHP 4)&lt;br /&gt;•    el tipo especial NULL (incluyendo variables no definidas)&lt;br /&gt;•    objetos SimpleXML creados desde etiquetas vacías&lt;br /&gt;&lt;br /&gt;Cualquier otro valor es considerado TRUE (incluyendo cualquier resource).&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;aviso&lt;/span&gt; : ¡-1 es considerado TRUE, como cualquier otro número diferente a cero (ya sea negativo o positivo)!&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;var_dump((bool) "");        // bool(false)&lt;br /&gt;var_dump((bool) 1);         // bool(true)&lt;br /&gt;var_dump((bool) -2);        // bool(true)&lt;br /&gt;var_dump((bool) "foo");     // bool(true)&lt;br /&gt;var_dump((bool) 2.3e5);     // bool(true)&lt;br /&gt;var_dump((bool) array(12)); // bool(true)&lt;br /&gt;var_dump((bool) array());   // bool(false)&lt;br /&gt;var_dump((bool) "false");   // bool(true)&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-8165479372373760271?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/8165479372373760271/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=8165479372373760271' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/8165479372373760271'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/8165479372373760271'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/tipo-de-datos-booleanos-en-php.html' title='Tipo de datos Booleanos en Php'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4372287333414387649</id><published>2008-02-17T19:28:00.000-02:00</published><updated>2008-02-17T19:29:00.205-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tipo de datos'/><title type='text'>Datos Enteros en Php</title><content type='html'>Un integer es un número del conjunto Z = {..., -2, -1, 0, 1, 2, ...}.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Sintaxis&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Los enteros pueden ser especificados en notación decimal (base-10), hexadecimal (base-16) u octal (base-8), opcionalmente precedidos por un signo (- o +).&lt;br /&gt;Si usa la notación octal, debe preceder el número con un 0 (cero), para usar la notación hexadecimal, preceda el número con 0x.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ejemplo: Literales tipo entero&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$a = 1234; // número decimal&lt;br /&gt;$a = -123; // un número negativo&lt;br /&gt;$a = 0123; // número octal (equivalente al 83 decimal)&lt;br /&gt;$a = 0x1A; // número hexadecimal (equivalente al 26 decimal)&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Formalmente, la posible estructura para literales enteros es:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;decimal     : [1-9][0-9]*&lt;br /&gt;               | 0&lt;br /&gt;&lt;br /&gt;hexadecimal : 0[xX][0-9a-fA-F]+&lt;br /&gt;&lt;br /&gt;octal       : 0[0-7]+&lt;br /&gt;&lt;br /&gt;integer     : [+-]?decimal&lt;br /&gt;               | [+-]?hexadecimal&lt;br /&gt;               | [+-]?octal&lt;/pre&gt;&lt;br /&gt;   &lt;br /&gt;El tamaño de un entero es dependiente de la plataforma, aunque un valor máximo de aproximadamente dos billones es el valor usual (lo que es un valor de 32 bits con signo). PHP no soporta enteros sin signo. El tamaño de un entero puede determinarse a partir de PHP_INT_SIZE, o el valor máximo de PHP_INT_MAX a partir de PHP 4.4.0 y PHP 5.0.5.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;aviso &lt;/span&gt;: Si un dígito inválido es pasado a un entero octal (p.ej. 8 o 9), el resto del número es ignorado.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ejemplo: Curiosidad de valores octales&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;var_dump(01090); // 010 octal = 8 decimal&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Desbordamiento de enteros&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Si especifica un número más allá de los límites del tipo integer, será interpretado en su lugar como un float. Asimismo, si realiza una operación que resulta en un número más allá de los límites del tipo integer, un float es retornado en su lugar.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$numero_grande =  2147483647;&lt;br /&gt;var_dump($numero_grande);&lt;br /&gt;// salida: int(2147483647)&lt;br /&gt;&lt;br /&gt;$numero_grande =  2147483648;&lt;br /&gt;var_dump($numero_grande);&lt;br /&gt;// salida: float(2147483648)&lt;br /&gt;&lt;br /&gt;// también es cierto para enteros hexadecimales especificados entre 2^31 y 2^32-1:&lt;br /&gt;var_dump( 0xffffffff );&lt;br /&gt;// salida: float(4294967295)&lt;br /&gt;&lt;br /&gt;// esto no ocurre con los enteros indicados como hexadecimales más allá de 2^32-1:&lt;br /&gt;var_dump( 0x100000000 );&lt;br /&gt;// salida: int(2147483647)&lt;br /&gt;&lt;br /&gt;$millon = 1000000;&lt;br /&gt;$numero_grande =  50000 * $millon;&lt;br /&gt;var_dump($numero_grande);&lt;br /&gt;// salida: float(50000000000)&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;No hay un operador de división de enteros en PHP. 1/2 produce el float 0.5. Puede moldear el valor a un entero para asegurarse de redondearlo hacia abajo, o puede usar la función round().&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;var_dump(25/7);         // float(3.5714285714286)&lt;br /&gt;var_dump((int) (25/7)); // int(3)&lt;br /&gt;var_dump(round(25/7));  // float(4)&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Conversión a entero&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Para convertir explícitamente un valor a integer, use alguno de los moldeamientos (int) o (integer). Sin embargo, en la mayoría de casos no necesita usar el moldeamiento, ya que un valor será convertido automáticamente si un operador, función o estructura de control requiere un argumento tipo integer. También puede convertir un valor a entero con la función intval().&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Desde booleans&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;FALSE producirá 0 (cero), y TRUE producirá 1 (uno).&lt;br /&gt;&lt;br /&gt;Desde números de punto flotante&lt;br /&gt;&lt;br /&gt;Cuando se realizan conversiones desde un flotante a un entero, el número será redondeado hacia cero.&lt;br /&gt;Si el flotante se encuentra más allá de los límites del entero (usualmente +/- 2.15e+9 = 2^31), el resultado es indefinido, ya que el flotante no tiene suficiente precisión para dar un resultado entero exacto. No se producirá una advertencia, ¡ni siquiera una noticia en este caso!&lt;br /&gt;aviso : Nunca moldee una fracción desconocida a integer, ya que esto en ocasiones produce resultados inesperados.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;echo (int) ( (0.1+0.7) * 10 ); // imprime 7!&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Desde otros tipos&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;El comportamiento de convertir desde entero no es definido para otros tipos. Actualmente, el comportamiento es el mismo que si el valor fuera antes convertido a booleano. Sin embargo, no confíe en este comportamiente, ya que puede ser modificado sin aviso.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4372287333414387649?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4372287333414387649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4372287333414387649' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4372287333414387649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4372287333414387649'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/datos-enteros-en-php.html' title='Datos Enteros en Php'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4783032878171985475</id><published>2008-02-12T18:32:00.000-02:00</published><updated>2008-02-12T18:34:31.836-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structures in Php: include_once()</title><content type='html'>The include_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include() statement, with the only difference being that if the code from a file has already been included, it will not be included again. As the name suggests, it will be included just once.&lt;br /&gt;include_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.&lt;br /&gt;For more examples on using require_once() and include_once(), look at the » PEAR code included in the latest PHP source code distributions.&lt;br /&gt;Return values are the same as with include(). If the file was already included, this function returns TRUE&lt;br /&gt;&lt;br /&gt;Note: include_once() was added in PHP 4.0.1&lt;br /&gt;&lt;br /&gt;Note: Be aware, that the behaviour of include_once() and require_once() may not be what you expect on a non case sensitive operating system (such as Windows).&lt;br /&gt;&lt;br /&gt;Example: include_once() is case insensitive on Windows&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;include_once "a.php"; // this will include a.php&lt;br /&gt;include_once "A.php"; // this will include a.php again on Windows! (PHP 4 only)&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This behaviour changed in PHP 5 - the path is normalized first so that C:\PROGRA~1\A.php is realized the same as C:\Program Files\a.php and the file is included just once.&lt;br /&gt;&lt;br /&gt;Warning:&lt;br /&gt;&lt;br /&gt;Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4783032878171985475?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4783032878171985475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4783032878171985475' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4783032878171985475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4783032878171985475'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structures-in-php-includeonce.html' title='Control structures in Php: include_once()'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-63322621474449389</id><published>2008-02-12T18:28:00.000-02:00</published><updated>2008-02-12T18:31:56.111-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structures in Php: require_once()</title><content type='html'>The require_once() statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the require() statement, with the only difference being that if the code from a file has already been included, it will not be included again. &lt;br /&gt;require_once() should be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, and you want to be sure that it is included exactly once to avoid problems with function redefinitions, variable value reassignments, etc.&lt;br /&gt;For examples on using require_once() and include_once(), look at the » PEAR code included in the latest PHP source code distributions.&lt;br /&gt;Return values are the same as with include(). If the file was already included, this function returns TRUE&lt;br /&gt;&lt;br /&gt;Note: require_once() was added in PHP 4.0.1&lt;br /&gt;&lt;br /&gt;Note: Be aware, that the behaviour of require_once() and include_once() may not be what you expect on a non case sensitive operating system (such as Windows).&lt;br /&gt;&lt;br /&gt;Example: require_once() is case insensitive on Windows&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;require_once "a.php"; // this will include a.php&lt;br /&gt;require_once "A.php"; // this will include a.php again on Windows! (PHP 4 only)&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This behaviour changed in PHP 5 - the path is normalized first so that C:\PROGRA~1\A.php is realized the same as C:\Program Files\a.php and the file is required just once.&lt;br /&gt;&lt;br /&gt;Warning:&lt;br /&gt;&lt;br /&gt;Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-63322621474449389?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/63322621474449389/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=63322621474449389' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/63322621474449389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/63322621474449389'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structures-in-php-requireonce.html' title='Control structures in Php: require_once()'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-8023742327131392709</id><published>2008-02-12T18:24:00.000-02:00</published><updated>2008-02-12T18:28:17.452-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structures in Php: include()</title><content type='html'>The include() statement includes and evaluates the specified file.&lt;br /&gt;The documentation below also applies to require(). The two constructs are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well. Be warned that parse error in included file doesn't cause processing halting in PHP versions prior to PHP 4.3.5. Since this version, it does.&lt;br /&gt;Files for including are first looked for in each include_path entry relative to the current working directory, and then in the directory of current script. E.g. if your include_path is libraries, current working directory is /www/, you included include/a.php and there is include "b.php" in that file, b.php is first looked in /www/libraries/ and then in /www/include/. If filename begins with ./ or ../, it is looked only in the current working directory.&lt;br /&gt;When a file is included, the code it contains inherits the variable scope of the line on which the include occurs. Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope.&lt;br /&gt;&lt;br /&gt;Example: Basic include() example&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;vars.php&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$color = 'green';&lt;br /&gt;$fruit = 'apple';&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;test.php&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;echo "A $color $fruit"; // A&lt;br /&gt;&lt;br /&gt;include 'vars.php';&lt;br /&gt;&lt;br /&gt;echo "A $color $fruit"; // A green apple&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If the include occurs inside a function within the calling file, then all of the code contained in the called file will behave as though it had been defined inside that function. So, it will follow the variable scope of that function. An exception to this rule are magic constants which are evaluated by the parser before the include occurs.&lt;br /&gt;&lt;br /&gt;Example: Including within functions&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;function foo()&lt;br /&gt;{&lt;br /&gt;    global $color;&lt;br /&gt;&lt;br /&gt;    include 'vars.php';&lt;br /&gt;&lt;br /&gt;    echo "A $color $fruit";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* vars.php is in the scope of foo() so     *&lt;br /&gt; * $fruit is NOT available outside of this  *&lt;br /&gt; * scope.  $color is because we declared it *&lt;br /&gt; * as global.                               */&lt;br /&gt;&lt;br /&gt;foo();                    // A green apple&lt;br /&gt;echo "A $color $fruit";   // A green&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;When a file is included, parsing drops out of PHP mode and into HTML mode at the beginning of the target file, and resumes again at the end. For this reason, any code inside the target file which should be executed as PHP code must be enclosed within valid PHP start and end tags.&lt;br /&gt;If "URL fopen wrappers" are enabled in PHP (which they are in the default configuration), you can specify the file to be included using a URL (via HTTP or other supported wrapper, instead of a local pathname. If the target server interprets the target file as PHP code, variables may be passed to the included file using a URL request string as used with HTTP GET. This is not strictly speaking the same thing as including the file and having it inherit the parent file's variable scope; the script is actually being run on the remote server and the result is then being included into the local script.&lt;br /&gt;&lt;br /&gt;Warning:&lt;br /&gt;&lt;br /&gt;Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.&lt;br /&gt;&lt;br /&gt;Example: include() through HTTP&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;/* This example assumes that www.example.com is configured to parse .php&lt;br /&gt; * files and not .txt files. Also, 'Works' here means that the variables&lt;br /&gt; * $foo and $bar are available within the included file. */&lt;br /&gt;&lt;br /&gt;// Won't work; file.txt wasn't handled by www.example.com as PHP&lt;br /&gt;include 'http://www.example.com/file.txt?foo=1&amp;amp;bar=2';&lt;br /&gt;&lt;br /&gt;// Won't work; looks for a file named 'file.php?foo=1&amp;amp;bar=2' on the&lt;br /&gt;// local filesystem.&lt;br /&gt;include 'file.php?foo=1&amp;amp;bar=2';&lt;br /&gt;&lt;br /&gt;// Works.&lt;br /&gt;include 'http://www.example.com/file.php?foo=1&amp;amp;bar=2';&lt;br /&gt;&lt;br /&gt;$foo = 1;&lt;br /&gt;$bar = 2;&lt;br /&gt;include 'file.txt';  // Works.&lt;br /&gt;include 'file.php';  // Works.&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Security warning&lt;br /&gt;&lt;br /&gt;Remote file may be processed at the remote server (depending on the file extension and the fact if the remote server runs PHP or not) but it still has to produce a valid PHP script because it will be processed at the local server. If the file from the remote server should be processed there and outputted only, readfile() is much better function to use. Otherwise, special care should be taken to secure the remote script to produce a valid and desired code.&lt;br /&gt;Handling Returns: It is possible to execute a return() statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. You can take the value of the include call as you would a normal function. This is not, however, possible when including remote files unless the output of the remote file has valid PHP start and end tags (as with any local file). You can declare the needed variables within those tags and they will be introduced at whichever point the file was included.&lt;br /&gt;Because include() is a special language construct, parentheses are not needed around its argument. Take care when comparing return value.&lt;br /&gt;&lt;br /&gt;Example: Comparing return value of include&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;// won't work, evaluated as include(('vars.php') == 'OK'), i.e. include('')&lt;br /&gt;if (include('vars.php') == 'OK') {&lt;br /&gt;    echo 'OK';&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// works&lt;br /&gt;if ((include 'vars.php') == 'OK') {&lt;br /&gt;    echo 'OK';&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note: In PHP 3, the return may not appear inside a block unless it's a function block, in which case the return() applies to that function and not the whole file.&lt;br /&gt;&lt;br /&gt;Example: include() and the return() statement&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;return.php&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$var = 'PHP';&lt;br /&gt;&lt;br /&gt;return $var;&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;noreturn.php&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$var = 'PHP';&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;testreturns.php&lt;br /&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$foo = include 'return.php';&lt;br /&gt;&lt;br /&gt;echo $foo; // prints 'PHP'&lt;br /&gt;&lt;br /&gt;$bar = include 'noreturn.php';&lt;br /&gt;&lt;br /&gt;echo $bar; // prints 1&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;$bar is the value 1 because the include was successful. Notice the difference between the above examples. The first uses return() within the included file while the other does not. If the file can't be included, FALSE is returned and E_WARNING is issued.&lt;br /&gt;If there are functions defined in the included file, they can be used in the main file independent if they are before return() or after. If the file is included twice, PHP 5 issues fatal error because functions were already declared, while PHP 4 doesn't complain about functions defined after return(). It is recommended to use include_once() instead of checking if the file was already included and conditionally return inside the included file.&lt;br /&gt;Another way to "include" a PHP file into a variable is to capture the output by using the Output Control Functions with include(). For example:&lt;br /&gt;&lt;br /&gt;Example: Using output buffering to include a PHP file into a string&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;$string = get_include_contents('somefile.php');&lt;br /&gt;&lt;br /&gt;function get_include_contents($filename) {&lt;br /&gt;    if (is_file($filename)) {&lt;br /&gt;        ob_start();&lt;br /&gt;        include $filename;&lt;br /&gt;        $contents = ob_get_contents();&lt;br /&gt;        ob_end_clean();&lt;br /&gt;        return $contents;&lt;br /&gt;    }&lt;br /&gt;    return false;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In order to automatically include files within scripts, see also the auto_prepend_file and auto_append_file configuration options in php.ini.&lt;br /&gt;&lt;br /&gt;Note: Because this is a language construct and not a function, it cannot be called using variable functions&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-8023742327131392709?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/8023742327131392709/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=8023742327131392709' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/8023742327131392709'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/8023742327131392709'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structures-in-php-include.html' title='Control structures in Php: include()'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1137374965035725000</id><published>2008-02-12T18:16:00.000-02:00</published><updated>2008-02-12T18:18:39.573-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structures in php: require()</title><content type='html'>The require() statement includes and evaluates the specific file.&lt;br /&gt;require() includes and evaluates a specific file. Detailed information on how this inclusion works is described in the documentation for include().&lt;br /&gt;require() and include() are identical in every way except how they handle failure. They both produce a Warning, but require() results in a Fatal Error. In other words, don't hesitate to use require() if you want a missing file to halt processing of the page. include() does not behave this way, the script will continue regardless. Be sure to have an appropriate include_path setting as well.&lt;br /&gt;&lt;br /&gt;Example: Basic require() examples&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;require 'prepend.php';&lt;br /&gt;&lt;br /&gt;require $somefile;&lt;br /&gt;&lt;br /&gt;require ('somefile.txt');&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Note: Prior to PHP 4.0.2, the following applies: require() will always attempt to read the target file, even if the line it's on never executes. The conditional statement won't affect require(). However, if the line on which the require() occurs is not executed, neither will any of the code in the target file be executed. Similarly, looping structures do not affect the behaviour of require(). Although the code contained in the target file is still subject to the loop, the require() itself happens only once.&lt;br /&gt;&lt;br /&gt;Note: Because this is a language construct and not a function, it cannot be called using variable functions&lt;br /&gt;&lt;br /&gt;Warning:&lt;br /&gt;&lt;br /&gt;Windows versions of PHP prior to PHP 4.3.0 do not support accessing remote files via this function, even if allow_url_fopen is enabled.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p class="MsoNormal"&gt;&lt;span style="" lang="EN"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1137374965035725000?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1137374965035725000/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1137374965035725000' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1137374965035725000'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1137374965035725000'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structures-in-php-require.html' title='Control structures in php: require()'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-5566125106208635357</id><published>2008-02-12T18:12:00.000-02:00</published><updated>2008-02-12T18:14:15.966-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structures in Php: return</title><content type='html'>If called from within a function, the return() statement immediately ends execution of the current function, and returns its argument as the value of the function call. return() will also end the execution of an eval() statement or script file.&lt;br /&gt;If called from the global scope, then execution of the current script file is ended. If the current script file was include()ed or require()ed, then control is passed back to the calling file. Furthermore, if the current script file was include()ed, then the value given to return() will be returned as the value of the include() call. If return() is called from within the main script file, then script execution ends. If the current script file was named by the auto_prepend_file or auto_append_file configuration options in php.ini, then that script file's execution is ended.&lt;br /&gt;&lt;br /&gt;Note: Note that since return() is a language construct and not a function, the parentheses surrounding its arguments are not required. It is common to leave them out, and you actually should do so as PHP has less work to do in this case.&lt;br /&gt;&lt;br /&gt;Note: You should never use parentheses around your return variable when returning by reference, as this will not work. You can only return variables by reference, not the result of a statement. If you use return ($a); then you're not returning a variable, but the result of the expression ($a) (which is, of course, the value of $a).&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-5566125106208635357?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/5566125106208635357/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=5566125106208635357' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/5566125106208635357'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/5566125106208635357'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structures-in-php-return.html' title='Control structures in Php: return'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-8185437274157832148</id><published>2008-02-12T18:09:00.000-02:00</published><updated>2008-02-12T18:10:36.753-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structure in Php: declare</title><content type='html'>The declare construct is used to set execution directives for a block of code. The syntax of declare is similar to the syntax of other flow control constructs:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;declare (directive)&lt;br /&gt;    statement&lt;/pre&gt;&lt;br /&gt;    &lt;br /&gt;The directive section allows the behavior of the declare block to be set. Currently only one directive is recognized: the ticks directive.&lt;br /&gt;The statement part of the declare block will be executed -- how it is executed and what side effects occur during execution may depend on the directive set in the directive block.&lt;br /&gt;The declare construct can also be used in the global scope, affecting all code following it.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;// these are the same:&lt;br /&gt;&lt;br /&gt;// you can use this:&lt;br /&gt;declare(ticks=1) {&lt;br /&gt;    // entire script here&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// or you can use this:&lt;br /&gt;declare(ticks=1);&lt;br /&gt;// entire script here&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ticks&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A tick is an event that occurs for every N low-level statements executed by the parser within the declare block. The value for N is specified using ticks=N within the declare blocks's directive section.&lt;br /&gt;The event(s) that occur on each tick are specified using the register_tick_function(). See the example below for more details. Note that more than one event can occur for each tick.&lt;br /&gt;&lt;br /&gt;Example: Profile a section of PHP code&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;// A function that records the time when it is called&lt;br /&gt;function profile($dump = FALSE)&lt;br /&gt;{&lt;br /&gt;    static $profile;&lt;br /&gt;&lt;br /&gt;    // Return the times stored in profile, then erase it&lt;br /&gt;    if ($dump) {&lt;br /&gt;        $temp = $profile;&lt;br /&gt;        unset($profile);&lt;br /&gt;        return $temp;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    $profile[] = microtime();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Set up a tick handler&lt;br /&gt;register_tick_function("profile");&lt;br /&gt;&lt;br /&gt;// Initialize the function before the declare block&lt;br /&gt;profile();&lt;br /&gt;&lt;br /&gt;// Run a block of code, throw a tick every 2nd statement&lt;br /&gt;declare(ticks=2) {&lt;br /&gt;    for ($x = 1; $x &amp;lt; 50; ++$x) {&lt;br /&gt;        echo similar_text(md5($x), md5($x*$x)), "&amp;lt;br /&amp;gt;;";&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;// Display the data stored in the profiler&lt;br /&gt;print_r(profile(TRUE));&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The example profiles the PHP code within the 'declare' block, recording the time at which every second low-level statement in the block was executed. This information can then be used to find the slow areas within particular segments of code. This process can be performed using other methods: using ticks is more convenient and easier to implement.&lt;br /&gt;Ticks are well suited for debugging, implementing simple multitasking, background I/O and many other tasks.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-8185437274157832148?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/8185437274157832148/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=8185437274157832148' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/8185437274157832148'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/8185437274157832148'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structure-in-php-declare.html' title='Control structure in Php: declare'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-5990072625266212851</id><published>2008-02-12T18:01:00.000-02:00</published><updated>2008-02-12T18:06:09.911-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structures in php: switch</title><content type='html'>The switch statement is similar to a series of IF statements on the same expression. In many occasions, you may want to compare the same variable (or expression) with many different values, and execute a different piece of code depending on which value it equals to. This is exactly what the switch statement is for.&lt;br /&gt;&lt;br /&gt;Note: Note that unlike some other languages, the continue statement applies to switch and acts similar to break. If you have a switch inside a loop and wish to continue to the next iteration of the outer loop, use continue 2.&lt;br /&gt;&lt;br /&gt;Note: Note that switch/case does loose comparision.&lt;br /&gt;&lt;br /&gt;The following two examples are two different ways to write the same thing, one using a series of if and elseif statements, and the other using the switch statement:&lt;br /&gt;Example: switch structure&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;if ($i == 0) {&lt;br /&gt;    echo "i equals 0";&lt;br /&gt;} elseif ($i == 1) {&lt;br /&gt;    echo "i equals 1";&lt;br /&gt;} elseif ($i == 2) {&lt;br /&gt;    echo "i equals 2";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;switch ($i) {&lt;br /&gt;case 0:&lt;br /&gt;    echo "i equals 0";&lt;br /&gt;    break;&lt;br /&gt;case 1:&lt;br /&gt;    echo "i equals 1";&lt;br /&gt;    break;&lt;br /&gt;case 2:&lt;br /&gt;    echo "i equals 2";&lt;br /&gt;    break;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Example: switch structure allows usage of strings&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;switch ($i) {&lt;br /&gt;case "apple":&lt;br /&gt;    echo "i is apple";&lt;br /&gt;    break;&lt;br /&gt;case "bar":&lt;br /&gt;    echo "i is bar";&lt;br /&gt;    break;&lt;br /&gt;case "cake":&lt;br /&gt;    echo "i is cake";&lt;br /&gt;    break;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;It is important to understand how the switch statement is executed in order to avoid mistakes. The switch statement executes line by line (actually, statement by statement). In the beginning, no code is executed. Only when a case statement is found with a value that matches the value of the switch expression does PHP begin to execute the statements. PHP continues to execute the statements until the end of the switch block, or the first time it sees a break statement. If you don't write a break statement at the end of a case's statement list, PHP will go on executing the statements of the following case. For example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;switch ($i) {&lt;br /&gt;case 0:&lt;br /&gt;    echo "i equals 0";&lt;br /&gt;case 1:&lt;br /&gt;    echo "i equals 1";&lt;br /&gt;case 2:&lt;br /&gt;    echo "i equals 2";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here, if $i is equal to 0, PHP would execute all of the echo statements! If $i is equal to 1, PHP would execute the last two echo statements. You would get the expected behavior ('i equals 2' would be displayed) only if $i is equal to 2. Thus, it is important not to forget break statements (even though you may want to avoid supplying them on purpose under certain circumstances).&lt;br /&gt;In a switch statement, the condition is evaluated only once and the result is compared to each case statement. In an elseif statement, the condition is evaluated again. If your condition is more complicated than a simple compare and/or is in a tight loop, a switch may be faster.&lt;br /&gt;The statement list for a case can also be empty, which simply passes control into the statement list for the next case.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;switch ($i) {&lt;br /&gt;case 0:&lt;br /&gt;case 1:&lt;br /&gt;case 2:&lt;br /&gt;    echo "i is less than 3 but not negative";&lt;br /&gt;    break;&lt;br /&gt;case 3:&lt;br /&gt;    echo "i is 3";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;A special case is the default case. This case matches anything that wasn't matched by the other cases. For example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;switch ($i) {&lt;br /&gt;case 0:&lt;br /&gt;    echo "i equals 0";&lt;br /&gt;    break;&lt;br /&gt;case 1:&lt;br /&gt;    echo "i equals 1";&lt;br /&gt;    break;&lt;br /&gt;case 2:&lt;br /&gt;    echo "i equals 2";&lt;br /&gt;    break;&lt;br /&gt;default:&lt;br /&gt;    echo "i is not equal to 0, 1 or 2";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The case expression may be any expression that evaluates to a simple type, that is, integer or floating-point numbers and strings. Arrays or objects cannot be used here unless they are dereferenced to a simple type.&lt;br /&gt;The alternative syntax for control structures is supported with switches.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;switch ($i):&lt;br /&gt;case 0:&lt;br /&gt;    echo "i equals 0";&lt;br /&gt;    break;&lt;br /&gt;case 1:&lt;br /&gt;    echo "i equals 1";&lt;br /&gt;    break;&lt;br /&gt;case 2:&lt;br /&gt;    echo "i equals 2";&lt;br /&gt;    break;&lt;br /&gt;default:&lt;br /&gt;    echo "i is not equal to 0, 1 or 2";&lt;br /&gt;endswitch;&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-5990072625266212851?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/5990072625266212851/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=5990072625266212851' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/5990072625266212851'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/5990072625266212851'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structures-in-php-switch.html' title='Control structures in php: switch'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1781793216792864092</id><published>2008-02-12T17:56:00.000-02:00</published><updated>2008-02-12T17:59:31.854-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Contro strucrutes in Php: continue</title><content type='html'>continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration.&lt;br /&gt;Note: Note that in PHP the switch statement is considered a looping structure for the purposes of continue.&lt;br /&gt;continue accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;while (list($key, $value) = each($arr)) {&lt;br /&gt;    if (!($key % 2)) { // skip odd members&lt;br /&gt;        continue;&lt;br /&gt;    }&lt;br /&gt;    do_something_odd($value);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;$i = 0;&lt;br /&gt;while ($i++ &amp;lt; 5) {&lt;br /&gt;    echo "Outer&amp;lt;br /&amp;gt;\n";&lt;br /&gt;    while (1) {&lt;br /&gt;        echo "  Middle&amp;lt;br /&amp;gt;\n";&lt;br /&gt;        while (1) {&lt;br /&gt;            echo "  Inner&amp;lt;br /&amp;gt;\n";&lt;br /&gt;            continue 3;&lt;br /&gt;        }&lt;br /&gt;        echo "This never gets output.&amp;lt;br /&amp;gt;\n";&lt;br /&gt;    }&lt;br /&gt;    echo "Neither does this.&amp;lt;br /&amp;gt;\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Omitting the semicolon after continue can lead to confusion. Here's an example of what you shouldn't do.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&amp;lt;?php&lt;br /&gt;  for ($i = 0; $i &amp;lt; 5; ++$i) {&lt;br /&gt;      if ($i == 2)&lt;br /&gt;          continue&lt;br /&gt;      print "$i\n";&lt;br /&gt;  }&lt;br /&gt;?&amp;gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;One can expect the result to be :&lt;br /&gt;&lt;br /&gt;0&lt;br /&gt;1&lt;br /&gt;3&lt;br /&gt;4&lt;br /&gt;&lt;br /&gt;     &lt;br /&gt;but this script will output :&lt;br /&gt;&lt;br /&gt;2&lt;br /&gt;&lt;br /&gt;     &lt;br /&gt;because the return value of the print() call is int(1), and it will look like the optional numeric argument mentioned above.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1781793216792864092?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1781793216792864092/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1781793216792864092' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1781793216792864092'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1781793216792864092'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/contro-strucrutes-in-php-continue.html' title='Contro strucrutes in Php: continue'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1399306584717616836</id><published>2008-02-12T12:43:00.000-02:00</published><updated>2008-02-12T12:44:35.244-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structures in Php: break</title><content type='html'>break ends execution of the current for, foreach, while, do-while or switch structure.&lt;br /&gt;break accepts an optional numeric argument which tells it how many nested enclosing structures are to be broken out of.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$arr = array('one', 'two', 'three', 'four', 'stop', 'five');&lt;br /&gt;while (list(, $val) = each($arr)) {&lt;br /&gt;    if ($val == 'stop') {&lt;br /&gt;        break;    /* You could also write 'break 1;' here. */&lt;br /&gt;    }&lt;br /&gt;    echo "$val&amp;lt;br /&amp;gt;\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* Using the optional argument. */&lt;br /&gt;&lt;br /&gt;$i = 0;&lt;br /&gt;while (++$i) {&lt;br /&gt;    switch ($i) {&lt;br /&gt;    case 5:&lt;br /&gt;        echo "At 5&amp;lt;br /&amp;gt;\n";&lt;br /&gt;        break 1;  /* Exit only the switch. */&lt;br /&gt;    case 10:&lt;br /&gt;        echo "At 10; quitting&amp;lt;br /&amp;gt;\n";&lt;br /&gt;        break 2;  /* Exit the switch and the while. */&lt;br /&gt;    default:&lt;br /&gt;        break;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1399306584717616836?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1399306584717616836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1399306584717616836' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1399306584717616836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1399306584717616836'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structures-in-php-break.html' title='Control structures in Php: break'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-827316638536406587</id><published>2008-02-12T12:40:00.001-02:00</published><updated>2008-02-12T12:41:49.695-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control structures in php: foreach</title><content type='html'>PHP 4 introduced a foreach construct, much like Perl and some other languages. This simply gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error when you try to use it on a variable with a different data type or an uninitialized variable. There are two syntaxes; the second is a minor but useful extension of the first:&lt;br /&gt;&lt;br /&gt;foreach (array_expression as $value)&lt;br /&gt;    statement&lt;br /&gt;foreach (array_expression as $key =&amp;gt; $value)&lt;br /&gt;    statement&lt;br /&gt;&lt;br /&gt;    &lt;br /&gt;The first form loops over the array given by array_expression. On each loop, the value of the current element is assigned to $value and the internal array pointer is advanced by one (so on the next loop, you'll be looking at the next element).&lt;br /&gt;The second form does the same thing, except that the current element's key will be assigned to the variable $key on each loop.&lt;br /&gt;As of PHP 5, it is possible to iterate objects too.&lt;br /&gt;Note: When foreach first starts executing, the internal array pointer is automatically reset to the first element of the array. This means that you do not need to call reset() before a foreach loop.&lt;br /&gt;Note: Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it.&lt;br /&gt;&lt;br /&gt;As of PHP 5, you can easily modify array's elements by preceding $value with &amp;amp;. This will assign reference instead of copying the value.&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$arr = array(1, 2, 3, 4);&lt;br /&gt;foreach ($arr as &amp;amp;$value) {&lt;br /&gt;    $value = $value * 2;&lt;br /&gt;}&lt;br /&gt;// $arr is now array(2, 4, 6, 8)&lt;br /&gt;unset($value); // break the reference with the last element&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;This is possible only if iterated array can be referenced (i.e. is variable).&lt;br /&gt;Warning&lt;br /&gt;Reference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset().&lt;br /&gt;Note: foreach does not support the ability to suppress error messages using '@'.&lt;br /&gt;You may have noticed that the following are functionally identical:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$arr = array("one", "two", "three");&lt;br /&gt;reset($arr);&lt;br /&gt;while (list(, $value) = each($arr)) {&lt;br /&gt;    echo "Value: $value&amp;lt;br /&amp;gt;\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;foreach ($arr as $value) {&lt;br /&gt;    echo "Value: $value&amp;lt;br /&amp;gt;\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;The following are also functionally identical:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$arr = array("one", "two", "three");&lt;br /&gt;reset($arr);&lt;br /&gt;while (list($key, $value) = each($arr)) {&lt;br /&gt;    echo "Key: $key; Value: $value&amp;lt;br /&amp;gt;\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;foreach ($arr as $key =&amp;gt; $value) {&lt;br /&gt;    echo "Key: $key; Value: $value&amp;lt;br /&amp;gt;\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Some more examples to demonstrate usages:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;/* foreach example 1: value only */&lt;br /&gt;&lt;br /&gt;$a = array(1, 2, 3, 17);&lt;br /&gt;&lt;br /&gt;foreach ($a as $v) {&lt;br /&gt;   echo "Current value of \$a: $v.\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* foreach example 2: value (with key printed for illustration) */&lt;br /&gt;&lt;br /&gt;$a = array(1, 2, 3, 17);&lt;br /&gt;&lt;br /&gt;$i = 0; /* for illustrative purposes only */&lt;br /&gt;&lt;br /&gt;foreach ($a as $v) {&lt;br /&gt;    echo "\$a[$i] =&amp;gt; $v.\n";&lt;br /&gt;    $i++;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* foreach example 3: key and value */&lt;br /&gt;&lt;br /&gt;$a = array(&lt;br /&gt;    "one" =&amp;gt; 1,&lt;br /&gt;    "two" =&amp;gt; 2,&lt;br /&gt;    "three" =&amp;gt; 3,&lt;br /&gt;    "seventeen" =&amp;gt; 17&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;foreach ($a as $k =&amp;gt; $v) {&lt;br /&gt;    echo "\$a[$k] =&amp;gt; $v.\n";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* foreach example 4: multi-dimensional arrays */&lt;br /&gt;$a = array();&lt;br /&gt;$a[0][0] = "a";&lt;br /&gt;$a[0][1] = "b";&lt;br /&gt;$a[1][0] = "y";&lt;br /&gt;$a[1][1] = "z";&lt;br /&gt;&lt;br /&gt;foreach ($a as $v1) {&lt;br /&gt;    foreach ($v1 as $v2) {&lt;br /&gt;        echo "$v2\n";&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/* foreach example 5: dynamic arrays */&lt;br /&gt;&lt;br /&gt;foreach (array(1, 2, 3, 4, 5) as $v) {&lt;br /&gt;    echo "$v\n";&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-827316638536406587?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/827316638536406587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=827316638536406587' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/827316638536406587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/827316638536406587'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/control-structures-in-php-foreach.html' title='Control structures in php: foreach'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-7780958031110130693</id><published>2008-02-12T12:34:00.001-02:00</published><updated>2008-02-12T12:36:17.292-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='constants'/><title type='text'>Expressions in PHP</title><content type='html'>Expressions are the most important building stones of PHP. In PHP, almost anything you write is an expression. The simplest yet most accurate way to define an expression is "anything that has a value".&lt;br /&gt;&lt;br /&gt;The most basic forms of expressions are constants and variables. When you type "$a = 5", you're assigning '5' into $a. '5', obviously, has the value 5, or in other words '5' is an expression with the value of 5 (in this case, '5' is an integer constant).&lt;br /&gt;After this assignment, you'd expect $a's value to be 5 as well, so if you wrote $b = $a, you'd expect it to behave just as if you wrote $b = 5. In other words, $a is an expression with the value of 5 as well. If everything works right, this is exactly what will happen.&lt;br /&gt;Slightly more complex examples for expressions are functions. For instance, consider the following function:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;function foo ()&lt;br /&gt;{&lt;br /&gt;    return 5;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Assuming you're familiar with the concept of functions (if you're not, take a look at the chapter about functions), you'd assume that typing $c = foo() is essentially just like writing $c = 5, and you're right. Functions are expressions with the value of their return value. Since foo() returns 5, the value of the expression 'foo()' is 5. Usually functions don't just return a static value but compute something.&lt;br /&gt;&lt;br /&gt;Of course, values in PHP don't have to be integers, and very often they aren't. PHP supports four scalar value types: integer values, floating point values (float), string values and boolean values (scalar values are values that you can't 'break' into smaller pieces, unlike arrays, for instance). PHP also supports two composite (non-scalar) types: arrays and objects. Each of these value types can be assigned into variables or returned from functions.&lt;br /&gt;&lt;br /&gt;PHP takes expressions much further, in the same way many other languages do. PHP is an expression-oriented language, in the sense that almost everything is an expression. Consider the example we've already dealt with, '$a = 5'. It's easy to see that there are two values involved here, the value of the integer constant '5', and the value of $a which is being updated to 5 as well. But the truth is that there's one additional value involved here, and that's the value of the assignment itself. The assignment itself evaluates to the assigned value, in this case 5. In practice, it means that '$a = 5', regardless of what it does, is an expression with the value 5. Thus, writing something like '$b = ($a = 5)' is like writing '$a = 5; $b = 5;' (a semicolon marks the end of a statement). Since assignments are parsed in a right to left order, you can also write '$b = $a = 5'.&lt;br /&gt;&lt;br /&gt;Another good example of expression orientation is pre- and post-increment and decrement. Users of PHP and many other languages may be familiar with the notation of variable++ and variable--. These are increment and decrement operators. In PHP/FI 2, the statement '$a++' has no value (is not an expression), and thus you can't assign it or use it in any way. PHP enhances the increment/decrement capabilities by making these expressions as well, like in C. In PHP, like in C, there are two types of increment - pre-increment and post-increment. Both pre-increment and post-increment essentially increment the variable, and the effect on the variable is identical. The difference is with the value of the increment expression. Pre-increment, which is written '++$variable', evaluates to the incremented value (PHP increments the variable before reading its value, thus the name 'pre-increment'). Post-increment, which is written '$variable++' evaluates to the original value of $variable, before it was incremented (PHP increments the variable after reading its value, thus the name 'post-increment').&lt;br /&gt;A very common type of expressions are comparison expressions. These expressions evaluate to either FALSE or TRUE. PHP supports &amp;gt; (bigger than), &amp;gt;= (bigger than or equal to), == (equal), != (not equal), &amp;lt; (smaller than) and &amp;lt;= (smaller than or equal to). The language also supports a set of strict equivalence operators: === (equal to and same type) and !== (not equal to or not same type). These expressions are most commonly used inside conditional execution, such as if statements.&lt;br /&gt;&lt;br /&gt;The last example of expressions we'll deal with here is combined operator-assignment expressions. You already know that if you want to increment $a by 1, you can simply write '$a++' or '++$a'. But what if you want to add more than one to it, for instance 3? You could write '$a++' multiple times, but this is obviously not a very efficient or comfortable way. A much more common practice is to write '$a = $a + 3'. '$a + 3' evaluates to the value of $a plus 3, and is assigned back into $a, which results in incrementing $a by 3. In PHP, as in several other languages like C, you can write this in a shorter way, which with time would become clearer and quicker to understand as well. Adding 3 to the current value of $a can be written '$a += 3'. This means exactly "take the value of $a, add 3 to it, and assign it back into $a". In addition to being shorter and clearer, this also results in faster execution. The value of '$a += 3', like the value of a regular assignment, is the assigned value. Notice that it is NOT 3, but the combined value of $a plus 3 (this is the value that's assigned into $a). Any two-place operator can be used in this operator-assignment mode, for example '$a -= 5' (subtract 5 from the value of $a), '$b *= 7' (multiply the value of $b by 7), etc.&lt;br /&gt;&lt;br /&gt;There is one more expression that may seem odd if you haven't seen it in other languages, the ternary conditional operator:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;$first ? $second : $third&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;If the value of the first subexpression is TRUE (non-zero), then the second subexpression is evaluated, and that is the result of the conditional expression. Otherwise, the third subexpression is evaluated, and that is the value.&lt;br /&gt;The following example should help you understand pre- and post-increment and expressions in general a bit better:&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;function double($i)&lt;br /&gt;{&lt;br /&gt;    return $i*2;&lt;br /&gt;}&lt;br /&gt;$b = $a = 5;        /* assign the value five into the variable $a and $b */&lt;br /&gt;$c = $a++;          /* post-increment, assign original value of $a&lt;br /&gt;                       (5) to $c */&lt;br /&gt;$e = $d = ++$b;     /* pre-increment, assign the incremented value of&lt;br /&gt;                       $b (6) to $d and $e */&lt;br /&gt;&lt;br /&gt;/* at this point, both $d and $e are equal to 6 */&lt;br /&gt;&lt;br /&gt;$f = double($d++);  /* assign twice the value of $d before&lt;br /&gt;                       the increment, 2*6 = 12 to $f */&lt;br /&gt;$g = double(++$e);  /* assign twice the value of $e after&lt;br /&gt;                       the increment, 2*7 = 14 to $g */&lt;br /&gt;$h = $g += 10;      /* first, $g is incremented by 10 and ends with the&lt;br /&gt;                       value of 24. the value of the assignment (24) is&lt;br /&gt;                       then assigned into $h, and $h ends with the value&lt;br /&gt;                       of 24 as well. */&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Some expressions can be considered as statements. In this case, a statement has the form of 'expr' ';' that is, an expression followed by a semicolon. In '$b=$a=5;', $a=5 is a valid expression, but it's not a statement by itself. '$b=$a=5;' however is a valid statement.&lt;br /&gt;One last thing worth mentioning is the truth value of expressions. In many events, mainly in conditional execution and loops, you're not interested in the specific value of the expression, but only care about whether it means TRUE or FALSE. The constants TRUE and FALSE (case-insensitive) are the two possible boolean values. When necessary, an expression is automatically converted to boolean.&lt;br /&gt;PHP provides a full and powerful implementation of expressions, and documenting it entirely goes beyond the scope of this manual. The above examples should give you a good idea about what expressions are and how you can construct useful expressions. Throughout the rest of this manual we'll write expr to indicate any valid PHP expression.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-7780958031110130693?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/7780958031110130693/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=7780958031110130693' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7780958031110130693'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7780958031110130693'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/expressions-in-php.html' title='Expressions in PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1446734186292256481</id><published>2008-02-12T12:29:00.000-02:00</published><updated>2008-02-12T12:30:32.675-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='constants'/><title type='text'>Constants in PHP</title><content type='html'>A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script (except for magic constants, which aren't actually constants). A constant is case-sensitive by default. By convention, constant identifiers are always uppercase.&lt;br /&gt;The name of a constant follows the same rules as any label in PHP. A valid constant name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thusly: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*&lt;br /&gt;&lt;br /&gt;Example: Valid and invalid constant names&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;// Valid constant names&lt;br /&gt;define("FOO",     "something");&lt;br /&gt;define("FOO2",    "something else");&lt;br /&gt;define("FOO_BAR", "something more");&lt;br /&gt;&lt;br /&gt;// Invalid constant names&lt;br /&gt;define("2FOO",    "something");&lt;br /&gt;&lt;br /&gt;// This is valid, but should be avoided:&lt;br /&gt;// PHP may one day provide a magical constant&lt;br /&gt;// that will break your script&lt;br /&gt;define("__FOO__", "something");&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;Note: For our purposes here, a letter is a-z, A-Z, and the ASCII characters from 127 through 255 (0x7f-0xff).&lt;br /&gt;&lt;br /&gt;Like superglobals, the scope of a constant is global. You can access constants anywhere in your script without regard to scope.&lt;br /&gt;&lt;br /&gt;Syntax&lt;br /&gt;&lt;br /&gt;You can define a constant by using the define()-function. Once a constant is defined, it can never be changed or undefined.&lt;br /&gt;Only scalar data (boolean, integer, float and string) can be contained in constants. Do not define resource constants.&lt;br /&gt;You can get the value of a constant by simply specifying its name. Unlike with variables, you should not prepend a constant with a $. You can also use the function constant() to read a constant's value if you wish to obtain the constant's name dynamically. Use get_defined_constants() to get a list of all defined constants.&lt;br /&gt;Note: Constants and (global) variables are in a different namespace. This implies that for example TRUE and $TRUE are generally different.&lt;br /&gt;If you use an undefined constant, PHP assumes that you mean the name of the constant itself, just as if you called it as a string (CONSTANT vs "CONSTANT"). An error of level E_NOTICE will be issued when this happens. If you simply want to check if a constant is set, use the defined() function.&lt;br /&gt;&lt;br /&gt;These are the differences between constants and variables:&lt;br /&gt;•    Constants do not have a dollar sign ($) before them;&lt;br /&gt;•    Constants may only be defined using the define() function, not by simple assignment;&lt;br /&gt;•    Constants may be defined and accessed anywhere without regard to variable scoping rules;&lt;br /&gt;•    Constants may not be redefined or undefined once they have been set; and&lt;br /&gt;•    Constants may only evaluate to scalar values.&lt;br /&gt;&lt;br /&gt;Example: Defining Constants&lt;br /&gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;define("CONSTANT", "Hello world.");&lt;br /&gt;echo CONSTANT; // outputs "Hello world."&lt;br /&gt;echo Constant; // outputs "Constant" and issues a notice.&lt;br /&gt;?&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1446734186292256481?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1446734186292256481/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1446734186292256481' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1446734186292256481'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1446734186292256481'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/constants-in-php.html' title='Constants in PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-2663157471180416153</id><published>2008-02-08T20:06:00.001-02:00</published><updated>2008-02-08T20:10:30.221-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Variables'/><category scheme='http://www.blogger.com/atom/ns#' term='Syntax'/><title type='text'>Variables in PHP</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;" lang="EN-US"&gt;Variables in PHP are represented by a dollar sign followed by the name of the variable. The variable name is case-sensitive. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;Variable names follow the same rules as other labels in PHP. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*' &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;Note: For our purposes here, a letter is a-z, A-Z, and the ASCII characters from 127 through 255 (0x7f-0xff). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;Note: $this is a special variable that can't be assigned. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$var = 'Bob';&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$Var = 'Joe';&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;echo "$var, $Var";&lt;span style=""&gt;      &lt;/span&gt;// outputs "Bob, Joe"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$4site = 'not yet';&lt;span style=""&gt;     &lt;/span&gt;// invalid; starts with a number&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$_4site = 'not yet';&lt;span style=""&gt;    &lt;/span&gt;// valid; starts with an underscore&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$täyte = 'mansikka';&lt;span style=""&gt;    &lt;/span&gt;// valid; 'ä' is (Extended) ASCII 228.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;In PHP 3, variables are always assigned by value. That is to say, when you assign an expression to a variable, the entire value of the original expression is copied into the destination variable. This means, for instance, that after assigning one variable's value to another, changing one of those variables will have no effect on the other. For more information on this kind of assignment, see the chapter on Expressions. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;As of PHP 4, PHP offers another way to assign values to variables: assign by reference. This means that the new variable simply references (in other words, "becomes an alias for" or "points to") the original variable. Changes to the new variable affect the original, and vice versa. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;To assign by reference, simply prepend an ampersand (&amp;amp;) to the beginning of the variable which is being assigned (the source variable). For instance, the following code snippet outputs 'My name is Bob' twice: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$foo = 'Bob';&lt;span style=""&gt;              &lt;/span&gt;// Assign the value 'Bob' to $foo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$bar = &amp;amp;$foo;&lt;span style=""&gt;              &lt;/span&gt;// Reference $foo via $bar.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$bar = "My name is $bar";&lt;span style=""&gt;  &lt;/span&gt;// Alter $bar...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;echo $bar;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;echo $foo;&lt;span style=""&gt;                 &lt;/span&gt;// $foo is altered too.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;One important thing to note is that only named variables may be assigned by reference. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$foo = 25;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$bar = &amp;amp;$foo;&lt;span style=""&gt;      &lt;/span&gt;// This is a valid assignment.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$bar = &amp;amp;(24 * 7);&lt;span style=""&gt;  &lt;/span&gt;// Invalid; references an unnamed expression.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;function test()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style=""&gt;   &lt;/span&gt;return 25;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$bar = &amp;amp;test();&lt;span style=""&gt;    &lt;/span&gt;// Invalid.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;It is not necessary to initialize variables in PHP however it is a very good practice. Uninitialized variables have a default value of their type - FALSE, zero, empty string or an empty array. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;Example: Default values of uninitialized variables&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;echo ($unset_bool ? "true" : "false"); // false&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$unset_int += 25; // 0 + 25 =&amp;gt; 25&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;echo $unset_string . "abc"; // "" . "abc" =&amp;gt; "abc"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$unset_array[3] = "def"; // array() + array(3 =&amp;gt; "def") =&amp;gt; array(3 =&amp;gt; "def")&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;Relying on the default value of an uninitialized variable is problematic in the case of including one file into another which uses the same variable name. It is also a major security risk with register_globals turned on. E_NOTICE level error is issued in case of working with uninitialized variables, however not in the case of appending elements to the uninitialized array. isset() language construct can be used to detect if a variable has been already initialized.&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-2663157471180416153?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/2663157471180416153/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=2663157471180416153' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2663157471180416153'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2663157471180416153'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/variables-in-php.html' title='Variables in PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-7953297481846412093</id><published>2008-02-05T20:27:00.000-02:00</published><updated>2008-02-05T20:29:16.688-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Types'/><title type='text'>Floating data type in php</title><content type='html'>&lt;span style="font-size:100%;"&gt;&lt;span style="font-family: arial;" lang="EN-US"&gt;Floating point numbers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;Floating point numbers (AKA "floats", "doubles" or "real numbers") can be specified using any of the following syntaxes: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;?php&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$a = 1.234; &lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$b = 1.2e3; &lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;$c = 7E-10;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;?&gt; &lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;Formally: &lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;LNUM&lt;span style=""&gt;          &lt;/span&gt;[0-9]+&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;DNUM&lt;span style=""&gt;          &lt;/span&gt;([0-9]*[\.]{LNUM}) | ({LNUM}[\.][0-9]*)&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;EXPONENT_DNUM ( ({LNUM} | {DNUM}) [eE][+-]? &lt;span style="" lang="EN-US"&gt;{LNUM}) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;The size of a float is platform-dependent, although a maximum of ~1.8e308 with a precision of roughly 14 decimal digits is a common value (that's 64 bit IEEE format). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;Floating point precision&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;It is quite usual that simple decimal fractions like 0.1 or 0.7 cannot be converted into their internal binary counterparts without a little loss of precision. This can lead to confusing results: for example, floor((0.1+0.7)*10) will usually return 7 instead of the expected 8 as the result of the internal representation really being something like 7.9999999999.... &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;This is related to the fact that it is impossible to exactly express some fractions in decimal notation with a finite number of digits. For instance, 1/3 in decimal form becomes 0.3333333. . .. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;        &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;So never trust floating number results to the last digit and never compare floating point numbers for equality. If you really need higher precision, you should use the arbitrary precision math functions or gmp functions instead.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="" lang="EN-US"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-7953297481846412093?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/7953297481846412093/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=7953297481846412093' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7953297481846412093'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7953297481846412093'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/floating-data-type-in-php.html' title='Floating data type in php'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-3018356997095531766</id><published>2008-02-05T20:21:00.000-02:00</published><updated>2008-02-05T20:25:36.549-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Types'/><title type='text'>Integers data type in php</title><content type='html'>&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;/span&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;An integer is a number of the set Z = {..., -2, -1, 0, 1, 2, ...}. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Syntax&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;Integers can be specified in decimal (10-based), hexadecimal (16-based) or octal (8-based) notation, optionally preceded by a sign (- or +). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;If you use the octal notation, you must precede the number with a 0 (zero), to use hexadecimal notation precede the number with 0x. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Example: Integer literals&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;$a = 1234; // decimal number&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;$a = -123; // a negative number&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;$a = 0123; // octal number (equivalent to 83 decimal)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;$a = 0x1A; // hexadecimal number (equivalent to 26 decimal)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;?&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;Formally the possible structure for integer literals is: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;"&gt;decimal&lt;span style=""&gt;     &lt;/span&gt;: [1-9][0-9]*&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style=""&gt;            &lt;/span&gt;| 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;"&gt;hexadecimal : 0[xX][0-9a-fA-F]+&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;"&gt;octal&lt;span style=""&gt;       &lt;/span&gt;: 0[0-7]+&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;"&gt;integer&lt;span style=""&gt;     &lt;/span&gt;: [+-]?decimal&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style=""&gt;            &lt;/span&gt;| [+-]?hexadecimal&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style=""&gt;            &lt;/span&gt;| [+-]?octal&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family: Arial;"&gt;&lt;span style=""&gt;&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). PHP does not support unsigned integers. Integer size can be determined from PHP_INT_SIZE, maximum value from PHP_INT_MAX since PHP 4.4.0 and PHP 5.0.5. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Warning&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;If an invalid digit is passed to octal integer (i.e. 8 or 9), the rest of the number is ignored. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Example: Octal weirdness&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump(01090); // 010 octal = 8 decimal&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;?&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Integer overflow&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;If you specify a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, if you perform an operation that results in a number beyond the bounds of the integer type, a float will be returned instead. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;$large_number =&lt;span style=""&gt;  &lt;/span&gt;2147483647;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump($large_number);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;// output: int(2147483647)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;$large_number =&lt;span style=""&gt;  &lt;/span&gt;2147483648;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump($large_number);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;// output: float(2147483648)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;// it's true also for hexadecimal specified integers between 2^31 and 2^32-1:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump( 0xffffffff );&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;// output: float(4294967295)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;// this doesn't go for hexadecimal specified integers above 2^32-1:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump( 0x100000000 );&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;// output: int(2147483647)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;$million = 1000000;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;$large_number =&lt;span style=""&gt;  &lt;/span&gt;50000 * $million;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump($large_number);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;// output: float(50000000000)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;?&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Warning&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;Unfortunately, there was a bug in PHP so that this does not always work correctly when there are negative numbers involved. For example: when you do -50000 * $million, the result will be -429496728. However, when both operands are positive there is no problem. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;This is solved in &lt;span style="font-weight: bold;"&gt;PHP 4.1.0.&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;There is no integer division operator in PHP. 1/2 yields the float 0.5. You can cast the value to an integer to always round it downwards, or you can use the round() function. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump(25/7);&lt;span style=""&gt;         &lt;/span&gt;// float(3.5714285714286) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump((int) (25/7)); // int(3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;var_dump(round(25/7));&lt;span style=""&gt;  &lt;/span&gt;// float(4) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;?&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Converting to integer&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;To explicitly convert a value to integer, use either the (int) or the (integer) cast. However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires an integer argument. You can also convert a value to integer with the function intval(). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;From booleans&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;FALSE will yield 0 (zero), and TRUE will yield 1 (one). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;span style="font-weight: bold;"&gt;From floating point numbers&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;When converting from float to integer, the number will be rounded towards zero. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;If the float is beyond the boundaries of integer (usually +/- 2.15e+9 = 2^31), the result is undefined, since the float hasn't got enough precision to give an exact integer result. No warning, not even a notice will be issued in this case! &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Warning&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;Never cast an unknown fraction to integer, as this can sometimes lead to unexpected results. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;echo (int) ( (0.1+0.7) * 10 ); // echoes 7!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-family: Arial;" lang="EN-US"&gt;?&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-3018356997095531766?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/3018356997095531766/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=3018356997095531766' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3018356997095531766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3018356997095531766'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/integers-data-type-in-php.html' title='Integers data type in php'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-7027353766675317609</id><published>2008-02-05T20:17:00.001-02:00</published><updated>2008-02-05T20:18:40.086-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Types'/><title type='text'>Booleans data type in php</title><content type='html'>&lt;span style="" lang="EN-US"&gt;This is the easiest type. A boolean expresses a truth value. It can be either TRUE or FALSE. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Syntax&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;To specify a boolean literal, use either the keyword TRUE or FALSE. Both are case-insensitive. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;$foo = True; // assign the value TRUE to $foo&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;?&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;Usually you use some kind of operator which returns a boolean value, and then pass it on to a control structure. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;// == is an operator which test&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;// equality and returns a boolean&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;if ($action == "show_version") {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "The version is 1.23";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;// this is not necessary...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;if ($show_separators == TRUE) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "&lt;hr /&gt;\n";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;// ...because you can simply type&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;if ($show_separators) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "&lt;hr /&gt;\n";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;?&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Converting to boolean&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;To explicitly convert a value to boolean, use either the (bool) or the (boolean) cast. However, in most cases you do not need to use the cast, since a value will be automatically converted if an operator, function or control structure requires a boolean argument. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;When converting to boolean, the following values are considered FALSE: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;the boolean FALSE itself&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;the integer 0 (zero) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;the float 0.0 (zero) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;the empty string, and the string "0"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;an array with zero elements&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;an object with zero member variables (PHP 4 only)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;the special type NULL (including unset variables) &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;SimpleXML objects created from empty tags &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;Every other value is considered TRUE (including any resource). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Warning&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;-1 is considered TRUE, like any other non-zero (whether negative or positive) number! &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;var_dump((bool) "");&lt;span style=""&gt;        &lt;/span&gt;// bool(false)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;var_dump((bool) 1);&lt;span style=""&gt;         &lt;/span&gt;// bool(true)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;var_dump((bool) -2);&lt;span style=""&gt;        &lt;/span&gt;// bool(true)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;var_dump((bool) "foo");&lt;span style=""&gt;     &lt;/span&gt;// bool(true)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;var_dump((bool) 2.3e5);&lt;span style=""&gt;     &lt;/span&gt;// bool(true)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;var_dump((bool) array(12)); // bool(true)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;var_dump((bool) array());&lt;span style=""&gt;   &lt;/span&gt;// bool(false)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;var_dump((bool) "false");&lt;span style=""&gt;   &lt;/span&gt;// bool(true)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;?&gt; &lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-7027353766675317609?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/7027353766675317609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=7027353766675317609' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7027353766675317609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7027353766675317609'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/booleans-data-type-in-php.html' title='Booleans data type in php'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4810696805304447094</id><published>2008-02-05T20:12:00.000-02:00</published><updated>2008-02-05T20:14:35.838-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Data Types'/><title type='text'>Data Types in PHP</title><content type='html'>&lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;PHP supports eight primitive types.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;Four scalar types:&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;boolean &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;integer &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;float (floating-point number, aka 'double') &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;string &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;Two compound types: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;array &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;object &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style="font-weight: bold;"&gt;And finally two special types:&lt;/span&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;resource &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;NULL &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;This page also introduces some pseudo-types for readability reasons: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;mixed &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;number &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;callback &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;And the pseudo-variable $.... &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;You may also find some references to the type "double". Consider double the same as float, the two names exist only for historic reasons. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;The type of a variable is usually not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which that variable is used. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;Note: If you want to check out the type and value of a certain expression, use var_dump(). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;If you simply want a human-readable representation of the type for debugging, use gettype(). To check for a certain type, do not use gettype(), but use the is_type functions. Some examples: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;$a_bool = TRUE;&lt;span style=""&gt;   &lt;/span&gt;// a boolean&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;$a_str&lt;span style=""&gt;  &lt;/span&gt;= "foo";&lt;span style=""&gt;  &lt;/span&gt;// a string&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;$a_str2 = 'foo';&lt;span style=""&gt;  &lt;/span&gt;// a string&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;$an_int = 12;&lt;span style=""&gt;     &lt;/span&gt;// an integer&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;echo gettype($a_bool); // prints out:&lt;span style=""&gt;  &lt;/span&gt;boolean&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;echo gettype($a_str);&lt;span style=""&gt;  &lt;/span&gt;// prints out:&lt;span style=""&gt;  &lt;/span&gt;string&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;// If this is an integer, increment it by four&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;if (is_int($an_int)) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;$an_int += 4;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;// If $bool is a string, print it out&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;// (does not print out anything)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;if (is_string($a_bool)) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "String: $a_bool";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;?&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;If you would like to force a variable to be converted to a certain type, you may either cast the variable or use the settype() function on it. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4810696805304447094?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4810696805304447094/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4810696805304447094' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4810696805304447094'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4810696805304447094'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/data-types-in-php.html' title='Data Types in PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-2375921511940904649</id><published>2008-02-05T20:04:00.000-02:00</published><updated>2008-02-05T20:09:42.003-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Syntax'/><title type='text'>Comments in PHP</title><content type='html'>&lt;span style="" lang="EN-US"&gt;PHP supports 'C', 'C++' and Unix shell-style (Perl style) comments. For example: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;prez&gt;&lt;/prez&gt;&lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;    echo 'This is a test'; // This is a one-line c++ style comment&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;    /* This is a multi line comment&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;       &lt;/span&gt;    yet another line of comment */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;    echo 'This is yet another test';&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;    echo 'One Final Test'; # This is a one-line shell-style comment&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;?&amp;gt;  &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;The "one-line" comment styles only comment to the end of the line or the current block of PHP code, whichever comes first. This means that HTML code after // ... ?&amp;gt; or # ... ?&amp;gt; WILL be printed: ?&amp;gt; breaks out of PHP mode and returns to HTML mode, and // or # cannot influence that. If the asp_tags configuration directive is enabled, it behaves the same with // %&amp;gt; and # %&amp;gt;. However, the &amp;lt;/script&amp;gt; tag doesn't break out of PHP mode in a one-line comment. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;      &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&amp;lt;h1&amp;gt;This is an &amp;lt;?php # echo 'simple';?&amp;gt; example.&amp;lt;/h1&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&amp;lt;p&amp;gt;The header above will say 'This is an&lt;span style=""&gt;  &lt;/span&gt;example'.&amp;lt;/p&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;'C' style comments end at the first */ encountered. Make sure you don't nest 'C' style comments. It is easy to make this mistake if you are trying to comment out a large block of code. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;&lt;span style="" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="" lang="EN-US"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt; &lt;/span&gt;/* &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo 'This is a test'; /* This comment will cause a problem */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt; &lt;/span&gt;&lt;/span&gt;*/&lt;/p&gt;?&amp;gt; &lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-2375921511940904649?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/2375921511940904649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=2375921511940904649' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2375921511940904649'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2375921511940904649'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/comments-in-php.html' title='Comments in PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4866913005500596403</id><published>2008-02-05T19:57:00.000-02:00</published><updated>2008-02-05T20:01:55.921-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Syntax'/><title type='text'>Instruction separation in PHP</title><content type='html'>&lt;span style="font-family: arial;font-family:arial;font-size:100%;"  &gt;&lt;span style="" lang="EN-US"&gt;As in C or Perl, PHP requires instructions to be terminated with a semicolon at the end of each statement. The closing tag of a block of PHP code automatically implies a semicolon; you do not need to have a semicolon terminating the last line of a PHP block. The closing tag for the block will include the immediately trailing newline if one is present. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt; &lt;pre style="font-family: arial;"&gt;&lt;span style="font-size:100%;"&gt;   &lt;/span&gt;&lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo 'This is a test';&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;/span&gt;&lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&amp;lt;?php echo 'This is a test' ?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;/span&gt;&lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="" lang="EN-US"&gt;&amp;lt;?php echo 'We omitted the last closing tag';  &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt; &lt;/span&gt;&lt;/pre&gt; &lt;span style="font-family: arial;font-family:arial;font-size:100%;"  &gt;&lt;span lang="EN-US"  style="font-size:10;"&gt;Note: The closing tag of a PHP block at the end of a file is optional, and in some cases omitting it is helpful when using include() or require(), so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later. It is also handy if you use output buffering, and would not like to see added unwanted whitespace at the end of the parts generated by the included files.&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4866913005500596403?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4866913005500596403/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4866913005500596403' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4866913005500596403'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4866913005500596403'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/02/instruction-separation-in-php.html' title='Instruction separation in PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1927296175791189506</id><published>2008-01-29T11:52:00.000-02:00</published><updated>2008-01-29T12:00:48.829-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Syntax'/><title type='text'>PHP Basic syntax</title><content type='html'>&lt;span style="font-family: arial;font-size:100%;" lang="EN-US" &gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="font-family: arial;font-size:100%;" lang="EN-US" &gt;Escaping from HTML&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;When PHP parses a file, it looks for opening and closing tags, which tell PHP to start and stop interpreting the code between them. Parsing in this manner allows php to be embedded in all sorts of different documents, as everything outside of a pair of opening and closing tags is ignored by the PHP parser. Most of the time you will see php embedded in HTML documents, as in this example.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&amp;lt;p&amp;gt;This is going to be ignored.&amp;lt;/p&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&amp;lt;?php echo 'While this is going to be parsed.'; ?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&amp;lt;p&amp;gt;This will also be ignored.&amp;lt;/p&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;You can also use more advanced structures:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;Example#1 Advanced escaping&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;pre style="font-family: arial;"&gt;&lt;span style="font-size:100%;"&gt; &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;if ($expression) { &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;strong&amp;gt;This is true.&amp;lt;/strong&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;?php &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;} else { &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;strong&amp;gt;This is false.&amp;lt;/strong&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;?php &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt; &lt;/span&gt;&lt;/pre&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;This works as expected, because when PHP hits the ?&amp;gt; closing tags, it simply starts outputting whatever it finds (except for an immediately following newline - see instruction separation ) until it hits another opening tag. The example given here is contrived, of course, but for outputting large blocks of text, dropping out of PHP parsing mode is generally more efficient than sending all of the text through echo() or print().&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;There are four different pairs of opening and closing tags which can be used in php. Two of those, &amp;lt;?php ?&amp;gt; and &amp;lt;script language="php"&amp;gt; &amp;lt;/script&amp;gt;, are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file. As such, while some people find short tags and ASP style tags convenient, they are less portable, and generally not recommended.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;Note: Also note that if you are embedding PHP within XML or XHTML you will need to use the &amp;lt;?php ?&amp;gt; tags to remain compliant with standards.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;Example#2 PHP Opening and Closing Tags&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;pre style="font-family: arial;"&gt;&lt;span style="font-size:100%;"&gt; &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;1.&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;?php echo 'if you want to serve XHTML or XML documents, do like this'; ?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;2.&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;script language="php"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;        &lt;/span&gt;echo 'some editors (like FrontPage) don\'t&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;              &lt;/span&gt;like processing instructions';&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;/script&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;3.&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;? echo 'this is the simplest, an SGML processing instruction'; ?&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;?= expression ?&amp;gt; This is a shortcut for "&amp;lt;? echo expression ?&amp;gt;"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;4.&lt;span style=""&gt;  &lt;/span&gt;&amp;lt;% echo 'You may optionally use ASP-style tags'; %&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;    &lt;/span&gt;&amp;lt;%= $variable; # This is a shortcut for "&amp;lt;% echo . . ." %&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt; &lt;/span&gt;&lt;/pre&gt;   &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;While the tags seen in examples one and two are both always available, example one is the most commonly used, and recommended, of the two.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;Short tags (example three) are only available when they are enabled via the short_open_tag php.ini configuration file directive, or if php was configured with the --enable-short-tags option.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;&lt;/span&gt;Note: If you are using PHP 3 you may also enable short tags via the short_tags() function. This is only available in PHP 3!&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;ASP style tags (example four) are only available when they are enabled via the asp_tags php.ini configuration file directive.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;&lt;/span&gt;Note: Support for ASP tags was added in 3.0.4.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p style="font-family: arial;" class="MsoPlainText"&gt;&lt;span style=";font-size:100%;" lang="EN-US" &gt;&lt;span style=""&gt;&lt;/span&gt;Note: Using short tags should be avoided when developing applications or libraries that are meant for redistribution, or deployment on PHP servers which are not under your control, because short tags may not be supported on the target server. For portable, redistributable code, be sure not to use short tags.&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1927296175791189506?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1927296175791189506/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1927296175791189506' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1927296175791189506'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1927296175791189506'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/01/php-basic-syntax.html' title='PHP Basic syntax'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-2623670191154304282</id><published>2008-01-28T12:37:00.000-02:00</published><updated>2008-01-28T12:54:23.077-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control Structures in PHP: WHILE</title><content type='html'>&lt;span style="" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="" lang="EN-US"&gt;while loops are the simplest type of loop in PHP. They behave just like their C counterparts. The basic form of a while statement is: &lt;/span&gt; &lt;pre&gt;   &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;while (expr)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;statement&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/pre&gt;   &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration (each time PHP runs the statements in the loop is one iteration). Sometimes, if the while expression evaluates to FALSE from the very beginning, the nested statement(s) won't even be run once. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;Like with the if statement, you can group multiple statements within the same while loop by surrounding a group of statements with curly braces, or by using the alternate syntax: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;pre&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;while (expr):&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;statement&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;endwhile; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt; &lt;/pre&gt;   &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;The following examples are identical, and both print the numbers 1 through 10: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;pre&gt; &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;/span&gt;&lt;span style="" lang="EN-US"&gt;/* example 1 */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;$i = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;while ($i &lt;span style="font-family:Georgia,serif;"&gt;&amp;lt;&lt;/span&gt;= 10) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo $i++;&lt;span style=""&gt;  &lt;/span&gt;/* the printed value would be&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;                    &lt;/span&gt;$i before the increment&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;                    &lt;/span&gt;(post-increment) */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;&lt;br /&gt;/* example 2 */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;$i = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;while ($i &amp;lt;= 10):&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo $i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="" lang="EN-US"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;$i++;  &lt;p class="MsoPlainText"&gt;endwhile;&lt;/p&gt;?&amp;gt; &lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;  &lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-2623670191154304282?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/2623670191154304282/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=2623670191154304282' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2623670191154304282'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2623670191154304282'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/01/control-structures-in-php-while.html' title='Control Structures in PHP: WHILE'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-3621649997487835537</id><published>2008-01-25T11:31:00.000-02:00</published><updated>2008-01-25T11:38:49.945-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control Structures in PHP: IF</title><content type='html'>&lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;The if construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an if structure that is similar to that of C: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;pre&gt;&lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;if (expr)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;  &lt;/span&gt;&lt;span style=""&gt;  &lt;/span&gt;statement  &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;/pre&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;As described in the section about expressions, expression is evaluated to its Boolean value. If expression evaluates to TRUE, PHP will execute statement, and if it evaluates to FALSE - it'll ignore it. More information about what values evaluate to FALSE can be found in the 'Converting to boolean' section. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;The following example would display a is bigger than b if $a is bigger than $b: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;pre&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt; &amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;if ($a &amp;gt; $b)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "a is bigger than b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;?&amp;gt;  &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;/pre&gt;   &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an if clause. Instead, you can group several statements into a statement group. For example, this code would display a is bigger than b if $a is bigger than $b, and would then assign the value of $a into $b: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;pre&gt;   &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt; &amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;if ($a &amp;gt; $b) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "a is bigger than b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;$b = $a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;?&amp;gt;  &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;/pre&gt;    &lt;p class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;If statements can be nested indefinitely within other if statements, which provides you with complete flexibility for conditional execution of the various parts of your program.&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;  &lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;/span&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-3621649997487835537?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/3621649997487835537/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=3621649997487835537' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3621649997487835537'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3621649997487835537'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/01/control-structures-in-php-if.html' title='Control Structures in PHP: IF'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-5058023657426191882</id><published>2008-01-24T18:09:00.000-02:00</published><updated>2008-01-24T18:20:26.980-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control Structures in PHP: FOR</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;for loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;    &lt;/div&gt; &lt;pre&gt; &lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;  for (expr1; expr2; expr3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;statement   &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;&lt;/div&gt; &lt;/pre&gt; &lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;At the end of each iteration, expr3 is evaluated (executed). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Each of the expressions can be empty or contain multiple expressions separated by commas. In expr2, all expressions separated by a comma are evaluated but the result is taken from the last part. expr2 being empty means the loop should be run indefinitely (PHP implicitly considers it as TRUE, like C). This may not be as useless as you might think, since often you'd want to end the loop using a conditional break statement instead of using the for truth expression. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Consider the following examples. All of them display the numbers 1 through 10: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt; &lt;pre&gt; &lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt; &amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;/* example 1 */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;for ($i = 1; $i &amp;lt;= 10; $i++) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo $i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;/* example 2 */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;for ($i = 1; ; $i++) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;if ($i &amp;gt; 10) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;   &lt;/span&gt;&lt;span style=""&gt;     &lt;/span&gt;break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo $i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;/* example 3 */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;$i = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;for (; ; ) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;if ($i &amp;gt; 10) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;        &lt;/span&gt;break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo $i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;$i++;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;/* example 4 */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;for ($i = 1, $j = 0; $i &amp;lt;= 10; $j += $i, print $i, $i++);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;?&amp;gt;   &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;/pre&gt; &lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;Of course, the first example appears to be the nicest one (or perhaps the fourth), but you may find that being able to use empty expressions in for loops comes in handy in many occasions. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;PHP also supports the alternate "colon syntax" for for loops. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;      &lt;/div&gt; &lt;pre&gt; &lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt; for (expr1; expr2; expr3):&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;statement &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;&lt;/span&gt;&lt;span style="font-family:Arial;"&gt;...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span style="font-family:Arial;"&gt;endfor;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;/pre&gt; &lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-5058023657426191882?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/5058023657426191882/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=5058023657426191882' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/5058023657426191882'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/5058023657426191882'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/01/control-structures-in-php-for.html' title='Control Structures in PHP: FOR'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-3521654566038755666</id><published>2008-01-24T17:54:00.001-02:00</published><updated>2008-01-24T18:20:51.380-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control Structures in PHP: ELSEIF</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;elseif, as its name suggests, is a combination of if and else. Like else, it extends an if statement to execute a different statement in case the original if expression evaluates to FALSE. However, unlike else, it will execute that alternative expression only if the elseif conditional expression evaluates to TRUE. For example, the following code would display a is bigger than b, a equal to b or a is smaller than b: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;    &lt;/div&gt; &lt;pre&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;if ($a &amp;gt; $b) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "a is bigger than b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;} elseif ($a == $b) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "a is equal to b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;} else {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "a is smaller than b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p class="MsoPlainText"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt; &lt;/pre&gt; &lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt;&lt;/o:p&gt;There may be several elseifs within the same if statement. The first elseif expression (if any) that evaluates to TRUE would be executed. In PHP, you can also write 'else if' (in two words) and the behavior would be identical to the one of 'elseif' (in a single word). The syntactic meaning is slightly different (if you're familiar with C, this is the same behavior) but the bottom line is that both would result in exactly the same behavior. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to FALSE, and the current elseif expression evaluated to TRUE. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p style="text-align: justify;" class="MsoPlainText"&gt;&lt;span style="font-size:100%;"&gt;&lt;span  lang="EN-US" style="font-family:Arial;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-3521654566038755666?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/3521654566038755666/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=3521654566038755666' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3521654566038755666'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3521654566038755666'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/01/control-structures-in-php-elseif.html' title='Control Structures in PHP: ELSEIF'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-3283966311548238236</id><published>2008-01-24T11:50:00.000-02:00</published><updated>2008-01-24T18:21:12.291-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control Structures in PHP: ELSE</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="" lang="EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:100%;"  lang="EN-US" &gt;Often you'd want to execute a statement if a certain condition is met, and a different statement if the condition is not met. This is what else is for. else extends an if statement to execute a statement in case the expression in the if statement evaluates to FALSE. For example, the following code would display a is bigger than b if $a is bigger than $b, and a is NOT bigger than b otherwise: &lt;/span&gt;&lt;pre  style="font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;if ($a &amp;gt; $b) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "a is bigger than b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;} else {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;echo "a is NOT bigger than b";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="font-size:100%;"&gt;  &lt;/span&gt;&lt;p class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;The else statement is only executed if the if expression evaluated to FALSE, and if there were any elseif expressions - only if they evaluated to FALSE as well (see elseif). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-3283966311548238236?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/3283966311548238236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=3283966311548238236' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3283966311548238236'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/3283966311548238236'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/01/control-structures-in-php-else.html' title='Control Structures in PHP: ELSE'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4965682118970808701</id><published>2008-01-22T19:58:00.000-02:00</published><updated>2008-01-24T18:21:35.987-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Control Structures'/><title type='text'>Control Structures in PHP: DO-WHILE</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style=";font-family:arial;font-size:100%;"  lang="EN-US" &gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;span style=";font-family:arial;font-size:100%;"  lang="EN-US" &gt;do-while loops are very similar to while loops, except the truth expression is checked at the end of each iteration instead of in the beginning. The main difference from regular while loops is that the first iteration of a do-while loop is guaranteed to run (the truth expression is only checked at the end of the iteration), whereas it's may not necessarily run with a regular while loop (the truth expression is checked at the beginning of each iteration, if it evaluates to FALSE right from the beginning, the loop execution would end immediately). &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;There is just one syntax for do-while loops: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="font-family: arial; text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;    $i = 0;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;    do {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;        echo $i;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;    } while ($i &amp;gt; 0);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;The above loop would run one time exactly, since after the first iteration, when truth expression is checked, it evaluates to FALSE ($i is not bigger than 0) and the loop execution ends. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;    &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;Advanced C users may be familiar with a different usage of the do-while loop, to allow stopping execution in the middle of code blocks, by encapsulating them with do-while (0), and using the break statement. The following code fragment demonstrates this: &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="text-align: justify;"&gt;  &lt;/div&gt;&lt;p  style="text-align: justify;font-family:arial;" class="MsoPlainText"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&amp;lt;?php&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;    do {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;        if ($i &amp;lt; 5) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;            echo "i is not big enough";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;            break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;        }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;        $i *= $factor;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;        if ($i &amp;lt; $minimum_limit) {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;        &lt;/span&gt;            break;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;        }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;   &lt;/span&gt;        echo "i is ok";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;span style=""&gt;    &lt;/span&gt;        /* process i */&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;    } while (0);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;?&amp;gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;/span&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;o:p&gt;&lt;br /&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;Don't worry if you don't understand this right away or at all. You can code scripts and even powerful scripts without using this 'feature'. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  class="MsoPlainText" style="font-family:arial;"&gt;&lt;span lang="EN-US"  style="font-size:100%;"&gt;&lt;o:p&gt; &lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4965682118970808701?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4965682118970808701/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4965682118970808701' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4965682118970808701'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4965682118970808701'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2008/01/control-structures-in-php-do-while.html' title='Control Structures in PHP: DO-WHILE'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4282689241337014548</id><published>2007-11-28T16:20:00.001-03:00</published><updated>2008-02-05T19:50:43.357-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Store and saving binary data (images, coding, etc.) into MySql Database with PHP</title><content type='html'>&lt;div  style="text-align: center; color: rgb(204, 204, 204);font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://mfw-php.blogspot.com/2007/11/almacenamiento-de-objetos-binarios.html"&gt;leer este articulo en español&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt; &lt;/p&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;An interesting topic in &lt;span style="font-weight: bold;"&gt;Mysql&lt;/span&gt; is to use the database to &lt;span style="font-weight: bold;"&gt;store binary data&lt;/span&gt;, such as images or html code. &lt;/span&gt; &lt;span style="color: rgb(204, 204, 204);"&gt; The first step is to create the database:&lt;/span&gt;&lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;CREATE TABLE binary_data (&lt;br /&gt;id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;descripction CHAR(50),&lt;br /&gt;bin_data LONGBLOB,&lt;br /&gt;filename CHAR(50),&lt;br /&gt;filesize CHAR(50),&lt;br /&gt;filetype CHAR(50)&lt;br /&gt;);&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;The following script can be used to &lt;span style="font-weight: bold;"&gt;insert binary objects in the database&lt;/span&gt; from a browser. Note that the tag is used input type = "file" a form html to upload a file.&lt;/span&gt;&lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);font-size:85%;" &gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;HTML&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;HEAD&amp;gt;&amp;lt;TITLE&amp;gt;Store and saving binary data (images, coding,&lt;br /&gt;etc.) into MySql Database with PHP &lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;/TITLE&amp;gt;&amp;lt;/HEAD&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;BODY&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;if ($submit) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;Code that runs if I press the submit button&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:85%;" &gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;MYSQL_CONNECT( "localhost", "root", "password");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;mysql_select_db( "binary_data");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;$data = addslashes(fread(fopen($form_data, "r"),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;filesize($form_data)));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;$result=MYSQL_QUERY( "INSERT INTO binary_data(description,&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bin_data,filename,&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;filesize,filetype) ". "VALUES&lt;br /&gt;('$form_description','$data',&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;'$form_data_name',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;'$form_data_size','$form_data_type')");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;$id= mysql_insert_id();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;print "&amp;lt;p&amp;gt;Database ID: &amp;lt;b&amp;gt;$id&amp;lt;/b&amp;gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;MYSQL_CLOSE();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;} else {&lt;/span&gt;&lt;br /&gt;&lt;i style="color: rgb(204, 204, 204);"&gt;// else &lt;/i&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;bring up the form for new data:&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:85%;" &gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;form method="post" action=" &amp;lt;?php echo $PHP_SELF; ?&amp;gt;"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;enctype="multipart/form-data"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;File Description:&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;input type="text" name="form_description" size="40"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;br&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size:85%;"&gt;Upload file to the database:&lt;/span&gt;&lt;span style="color: rgb(51, 255, 51);font-size:85%;" &gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;input type="file" name="form_data" size="40"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;p&amp;gt;&amp;lt;input type="submit" name="submit" value="submit"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;/BODY&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;/HTML&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;Note the use of &lt;span style="font-weight: bold;"&gt;$ PHP_SELF&lt;/span&gt; predefined variable that contains the name of the script. This form is called himself regardless of the name that comes to the file.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;The following script (getdata.php) can be used to recover data from the database, noting that the script expects to receive the variable $ id with id register to recover from the table.&lt;/span&gt;&lt;p face="arial" style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="left"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;br /&gt;if($id) {&lt;br /&gt;@MYSQL_CONNECT( "localhost", "root", "contraseña");&lt;br /&gt;@mysql_select_db( "binary_data");&lt;br /&gt;$query = "select bin_data,filetype from binary_data where id=$id";&lt;br /&gt;$result = @MYSQL_QUERY($query);&lt;br /&gt;$data = @MYSQL_RESULT($result,0, "bin_data");&lt;br /&gt;$type = @MYSQL_RESULT($result,0, "filetype");&lt;br /&gt;Header( "Content-type: $type");&lt;br /&gt;echo $data;&lt;br /&gt;};&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt; &lt;p face="arial" style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="left"&gt;To use an image that is obtained from the database can be used:&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204); font-family: arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;img src="getdata.php?id=3"&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p face="arial" style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="left"&gt;Note as he passes the variable id to script to know what is the record to retrieve the base.&lt;/p&gt;  &lt;span style="color: rgb(204, 204, 204);font-family:arial;font-size:100%;"  &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="text-align: center; color: rgb(204, 204, 204);font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://mfw-php.blogspot.com/2007/11/almacenamiento-de-objetos-binarios.html"&gt;leer este articulo en español&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4282689241337014548?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4282689241337014548/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4282689241337014548' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4282689241337014548'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4282689241337014548'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2007/11/store-and-saving-binary-data-images.html' title='Store and saving binary data (images, coding, etc.) into MySql Database with PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-2774396060867354718</id><published>2007-11-28T12:17:00.000-03:00</published><updated>2008-02-05T19:51:13.716-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Almacenamiento de objetos binarios (imagenes, codigo, etc.) en MySQL desde PHP</title><content type='html'>&lt;div  style="text-align: center; color: rgb(204, 204, 204);font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://mfw-php.blogspot.com/2007/11/store-and-saving-binary-data-images.html"&gt;read this article in english&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt; &lt;/p&gt;    &lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;Un tema interesante en Mysql es usar la base de datos para guardar además de datos de tipo texto datos binarios como por ejemplo código html o imágenes.&lt;br /&gt;El primer paso es crear la base de datos:&lt;br /&gt;&lt;/span&gt; &lt;/p&gt;        &lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;CREATE TABLE binary_data (&lt;br /&gt;id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,&lt;br /&gt;descripction CHAR(50),&lt;br /&gt;bin_data LONGBLOB,&lt;br /&gt;filename CHAR(50),&lt;br /&gt;filesize CHAR(50),&lt;br /&gt;filetype CHAR(50)&lt;br /&gt;);&lt;/span&gt;&lt;/p&gt;   &lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;El siguiente script puede usarse para insertar objetos binarios en la base de datos desde un browser. Notar que se usa el tag input type=”file” de un form html para subir un archivo.&lt;/span&gt;&lt;/p&gt;                                   &lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;&lt;pre&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 255, 51);font-size:85%;" &gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;HTML&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;HEAD&amp;gt;&amp;lt;TITLE&amp;gt;Almacenamiento de datos binarios en una base&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;de datos MySql&amp;lt;/TITLE&amp;gt;&amp;lt;/HEAD&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;BODY&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;if ($submit) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;//codigo que se ejecuta si se presiono el botón submit&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;MYSQL_CONNECT( "localhost", "root", "contraseña");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;mysql_select_db( "binary_data");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;$data = addslashes(fread(fopen($form_data, "r"),&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;filesize($form_data)));&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;$result=MYSQL_QUERY( "INSERT INTO binary_data(description,&lt;br /&gt;&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;bin_data,filename,&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;filesize,filetype) ". "VALUES&lt;br /&gt;('$form_description','$data',&lt;/span&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;'$form_data_name',&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;'$form_data_size','$form_data_type')");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;$id= mysql_insert_id();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;print "&amp;lt;p&amp;gt;Database ID: &amp;lt;b&amp;gt;$id&amp;lt;/b&amp;gt;";&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;MYSQL_CLOSE();&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;} else {&lt;/span&gt;&lt;br /&gt;&lt;i style="color: rgb(204, 204, 204);"&gt;// sino mostrar el formulario para nuevos datos:&lt;/i&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;form method="post" action=" &amp;lt;?php echo $PHP_SELF; ?&amp;gt;"&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;enctype="multipart/form-data"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;File Description:&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;input type="text" name="form_description" size="40"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="1000000"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;br&amp;gt;Cargar archivo en base de datos:&amp;lt;br&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;input type="file" name="form_data" size="40"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;p&amp;gt;&amp;lt;input type="submit" name="submit" value="submit"&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;?php&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;/BODY&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(204, 204, 204);"&gt;&amp;lt;/HTML&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;Notar el uso de la variable predefinida $PHP_SELF que tiene el nombre del script de esta forma el formulario se llama a si  mismo independientemente del nombre que se le ponga al archivo.&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;El siguiente script (getdata.php) puede usarse para recuperar los datos desde la base de datos, notar que el script espera recibir la variable $id con el id del registro a recuperar de la tabla.&lt;/span&gt;&lt;/p&gt;              &lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;&amp;lt;?php&lt;br /&gt;if($id) {&lt;br /&gt;@MYSQL_CONNECT( "localhost", "root", "contraseña");&lt;br /&gt;@mysql_select_db( "binary_data");&lt;br /&gt;$query = "select bin_data,filetype from binary_data where id=$id";&lt;br /&gt;$result = @MYSQL_QUERY($query);&lt;br /&gt;$data = @MYSQL_RESULT($result,0, "bin_data");&lt;br /&gt;$type = @MYSQL_RESULT($result,0, "filetype");&lt;br /&gt;Header( "Content-type: $type");&lt;br /&gt;echo $data;&lt;br /&gt;};&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/span&gt; &lt;/p&gt; &lt;p  style="margin-bottom: 0cm; color: rgb(204, 204, 204);font-family:arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;Para usar una imagen que se obtiene de la base de datos se puede usar:&lt;/span&gt;&lt;/p&gt;  &lt;p style="margin-bottom: 0cm; color: rgb(204, 204, 204); font-family: arial;" align="left"&gt;&lt;span style="font-size:100%;"&gt;&lt;pre&gt;&lt;br /&gt;&amp;lt;img src="getdata.php?id=3"&amp;gt;&lt;br /&gt;&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p face="arial" style="margin-bottom: 0cm; color: rgb(204, 204, 204);" align="left"&gt;&lt;span style="font-size:100%;"&gt;Notar como se le pasa la variable id al script para saber cual es el registro a recuperar de la base.&lt;/span&gt;&lt;/p&gt;  &lt;span style="color: rgb(204, 204, 204);font-family:arial;font-size:100%;"  &gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;div  style="text-align: center; color: rgb(204, 204, 204);font-family:arial;"&gt;&lt;span style="font-size:100%;"&gt;&lt;a href="http://mfw-php.blogspot.com/2007/11/store-and-saving-binary-data-images.html"&gt;read this article in english&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-2774396060867354718?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/2774396060867354718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=2774396060867354718' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2774396060867354718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/2774396060867354718'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2007/11/almacenamiento-de-objetos-binarios.html' title='Almacenamiento de objetos binarios (imagenes, codigo, etc.) en MySQL desde PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-1289285716282454601</id><published>2007-11-24T09:32:00.000-03:00</published><updated>2008-02-05T19:51:45.267-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Capítulo 17: Manejo de Mail en PHP</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Conexión a un server IMAP o POP3:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;mail_handler=imap_open(string_mbox,user,password);&lt;br /&gt;&lt;br /&gt;Donde mbox es de la forma:&lt;br /&gt;{IP:PORT}MailBox&lt;br /&gt;&lt;br /&gt;Ejemplos:&lt;br /&gt;&lt;br /&gt;$mail=imap_open(“{190.190.190.190:143}INBOX”,”user”,”pass”);&lt;br /&gt;&lt;br /&gt;Conexión a la carpeta INBOX de un servidor IMAP (puerto 143)&lt;br /&gt;&lt;br /&gt;$mail=imap_open(“{190.190.190.190:110}”,”user”,”pass”);&lt;br /&gt;&lt;br /&gt;Conexión a la carpeta raíz de un servidor POP3 (puerto 110)&lt;br /&gt;&lt;br /&gt;Una vez establecida la conexión la función devuelve un handler que se utiliza en el resto de las funciones para acceder a las carpetas y mails dentro de las mismas.&lt;br /&gt;&lt;br /&gt;Ejemplo:&lt;br /&gt;&lt;br /&gt;$mbox = imap_open ("{your.imap.host:143}", "username", "password");&lt;br /&gt;echo "&lt;p&gt;&lt;/p&gt;&lt;h1&gt;Mailboxes&lt;/h1&gt;\n";&lt;br /&gt;$folders = imap_listmailbox ($mbox, "{your.imap.host:143}", "*");&lt;br /&gt;if ($folders == false) {&lt;br /&gt;echo "Call failed&lt;br /&gt;\n";&lt;br /&gt;} else {&lt;br /&gt;while (list ($key, $val) = each ($folders)) {&lt;br /&gt;echo $val."&lt;br /&gt;\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;echo "&lt;p&gt;&lt;/p&gt;&lt;h1&gt;Headers in INBOX&lt;/h1&gt;\n";&lt;br /&gt;$headers = imap_headers ($mbox);&lt;br /&gt;if ($headers == false) {&lt;br /&gt;echo "Call failed&lt;br /&gt;\n";&lt;br /&gt;} else {&lt;br /&gt;while (list ($key,$val) = each ($headers)) {&lt;br /&gt;echo $val."&lt;br /&gt;\n";&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;imap_close($mbox);&lt;br /&gt;&lt;br /&gt;Una vez terminada la conexión se usa:&lt;br /&gt;&lt;br /&gt;imap_close(mail_handler);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Manejo de MailBoxes:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;int=imap_createmailbox (mail_handler string_mbox)&lt;br /&gt;&lt;br /&gt;String mbox debe estar codificado con imap_utf7_encode() y el formato del string es el mismo que en imap_open.&lt;br /&gt;&lt;br /&gt;Ejemplo:&lt;br /&gt;&lt;br /&gt;$mbox = imap_open("{your.imap.host}","username","password",OP_HALFOPEN)&lt;br /&gt;|| die("can't connect: ".imap_last_error());&lt;br /&gt;$name1 = "phpnewbox";&lt;br /&gt;$name2 = imap_utf7_encode("phpnewböx");&lt;br /&gt;$newname = $name1;&lt;br /&gt;echo "Newname will be '$name1'&lt;br /&gt;\n";&lt;br /&gt;# we will now create a new mailbox "phptestbox" in your inbox folder,&lt;br /&gt;# check its status after creation and finaly remove it to restore&lt;br /&gt;# your inbox to its initial state&lt;br /&gt;if(@imap_createmailbox($mbox,imap_utf7_encode("{your.imap.host}INBOX.$newname"))) {&lt;br /&gt;$status = @imap_status($mbox,"{your.imap.host}INBOX.$newname",SA_ALL);&lt;br /&gt;if($status) {&lt;br /&gt;print("your new mailbox '$name1' has the following status:&lt;br /&gt;\n");&lt;br /&gt;print("Messages: ". $status-&gt;messages )."&lt;br /&gt;\n";&lt;br /&gt;print("Recent: ". $status-&gt;recent )."&lt;br /&gt;\n";&lt;br /&gt;print("Unseen: ". $status-&gt;unseen )."&lt;br /&gt;\n";&lt;br /&gt;print("UIDnext: ". $status-&gt;uidnext )."&lt;br /&gt;\n";&lt;br /&gt;print("UIDvalidity:". $status-&gt;uidvalidity)."&lt;br /&gt;\n";&lt;br /&gt;&lt;br /&gt;if(imap_renamemailbox($mbox,"{your.imap.host}INBOX.$newname","{your.imap.host}INBOX.$name2")) {&lt;br /&gt;echo "renamed new mailbox from '$name1' to '$name2'&lt;br /&gt;\n";&lt;br /&gt;$newname=$name2;&lt;br /&gt;} else {&lt;br /&gt;print "imap_renamemailbox on new mailbox failed: ".imap_last_error()."&lt;br /&gt;\n";&lt;br /&gt;}&lt;br /&gt;} else {&lt;br /&gt;print "imap_status on new mailbox failed: ".imap_last_error()."&lt;br /&gt;\n";&lt;br /&gt;}&lt;br /&gt;if(@imap_deletemailbox($mbox,"{your.imap.host}INBOX.$newname")) {&lt;br /&gt;print "new mailbox removed to restore initial state&lt;br /&gt;\n";&lt;br /&gt;} else {&lt;br /&gt;print "imap_deletemailbox on new mailbox failed:&lt;br /&gt;".implode("&lt;br /&gt;\n",imap_errors())."&lt;br /&gt;\n";&lt;br /&gt;}&lt;br /&gt;} else {&lt;br /&gt;print "could not create new mailbox: ".implode("&lt;br /&gt;\n",imap_errors())."&lt;br /&gt;\n";&lt;br /&gt;}&lt;br /&gt;imap_close($mbox);&lt;br /&gt;&lt;br /&gt;Devuelve true si pudo crear el mailbox o false en caso contrario.&lt;br /&gt;&lt;br /&gt;int=imap_deletemailbox (mail_handler, string_mbox);&lt;br /&gt;&lt;br /&gt;Elimina el mailbox indicado, el formato de mbox es el mismo que en imap_open.&lt;br /&gt;&lt;br /&gt;int=imap_renamemailbox (mail_handler, string_old_mbox, string_new_mbox)&lt;br /&gt;&lt;br /&gt;Permite renombrar un mailbox, el nombre del mailbox debe estar en el mismo formato que en imap_open.&lt;br /&gt;&lt;br /&gt;obj_array=imap_getmailboxes (mail_stream, string_ref, string_pattern)&lt;br /&gt;&lt;br /&gt;Devuelve un vector de objetos con información sobre los mailboxes&lt;br /&gt;&lt;br /&gt;Los objetos que se encuentran en el vector tienen seteados los siguientes data_members:&lt;br /&gt;&lt;br /&gt;· name – Nombre del mailbox (completo) encodeado, decodificar con imap_utf7_decode()&lt;br /&gt;· delimiter – Delimitador usado para separar la jerarquía de mailboxes&lt;br /&gt;· attributes – Es un bitmask que puede compararse con:&lt;br /&gt;- LATT_NOINFERIORS (el mailbox no tiene subcarpetas)&lt;br /&gt;- LATT_NOSELECT (es un mailbox no seleccionable)&lt;br /&gt;- LATT_MARKED (mailbox marcado)&lt;br /&gt;- LATT_UNMARKED (mailbox no marcado)&lt;br /&gt;&lt;br /&gt;Ejemplo:&lt;br /&gt;&lt;br /&gt;$mbox = imap_open("{your.imap.host}","username","password")&lt;br /&gt;|| die("can't connect: ".imap_last_error());&lt;br /&gt;$list = imap_getmailboxes($mbox,"{your.imap.host}","*");&lt;br /&gt;if(is_array($list)) {&lt;br /&gt;reset($list);&lt;br /&gt;while (list($key, $val) = each($list))&lt;br /&gt;{&lt;br /&gt;print "($key) ";&lt;br /&gt;print imap_utf7_decode($val-&gt;name).",";&lt;br /&gt;print "'".$val-&gt;delimiter."',";&lt;br /&gt;print $val-&gt;attributes."&lt;br /&gt;\n";&lt;br /&gt;}&lt;br /&gt;} else&lt;br /&gt;print "imap_getmailboxes failed: ".imap_last_error()."\n";&lt;br /&gt;imap_close($mbox);&lt;br /&gt;object=imap_status (mail_handler, string_mailbox, SA_ALL)&lt;br /&gt;&lt;br /&gt;SA_ALL es una constante para recuperar toda la información sobre el mailbox, devuelve un objeto con los siguientes data members seteados:&lt;br /&gt;&lt;br /&gt;· messages – número de mensajes en el mailbox&lt;br /&gt;· recent – número de mensajes recientes en el mailbox&lt;br /&gt;· unseen – número de mensajes no vistos en el mailbox&lt;br /&gt;&lt;br /&gt;Ejemplo:&lt;br /&gt;&lt;br /&gt;$mbox = imap_open("{your.imap.host}","username","password",OP_HALFOPEN)&lt;br /&gt;|| die("can't connect: ".imap_last_error());&lt;br /&gt;$status = imap_status($mbox,"{your.imap.host}INBOX",SA_ALL);&lt;br /&gt;if($status) {&lt;br /&gt;print("Messages: ". $status-&gt;messages )."&lt;br /&gt;\n";&lt;br /&gt;print("Recent: ". $status-&gt;recent )."&lt;br /&gt;\n";&lt;br /&gt;print("Unseen: ". $status-&gt;unseen )."&lt;br /&gt;\n";&lt;br /&gt;print("UIDnext: ". $status-&gt;uidnext )."&lt;br /&gt;\n";&lt;br /&gt;print("UIDvalidity:". $status-&gt;uidvalidity)."&lt;br /&gt;\n";&lt;br /&gt;} else&lt;br /&gt;print "imap_status failed: ".imap_lasterror()."\n";&lt;br /&gt;imap_close($mbox);&lt;br /&gt;&lt;br /&gt;int imap_num_msg (mail_handler)&lt;br /&gt;&lt;br /&gt;Devuelve el número de mensajes en el mailbox actual. (El abierto por el mail_handler)&lt;br /&gt;&lt;br /&gt;int imap_num_recent (mail_handler)&lt;br /&gt;&lt;br /&gt;Devuelve el número de mensajes recientes del mailbox correspondiente a mail_handler.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Manejo de mensajes:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;object=imap_fetchstructure (mail_handler, int msg_number)&lt;br /&gt;&lt;br /&gt;Devuelve un objeto con la estructura del mensaje recuperado:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Table 1. Returned Objects for imap_fetchstructure()&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;type                          Primary body type&lt;br /&gt;encoding                  Body transfer encoding&lt;br /&gt;ifsubtype                 True if there is a subtype string&lt;br /&gt;subtype                   MIME subtype&lt;br /&gt;ifdescription            True if there is a description string&lt;br /&gt;description              Content description string&lt;br /&gt;ifid                            True if there is an identification string&lt;br /&gt;id                               Identification string&lt;br /&gt;lines                          Number of lines&lt;br /&gt;bytes                        Number of bytes&lt;br /&gt;ifdisposition             True if there is a disposition string&lt;br /&gt;disposition               Disposition string&lt;br /&gt;ifdparameters         True if the dparameters array exists&lt;br /&gt;dparameters           Disposition parameter array&lt;br /&gt;ifparameters           True if the parameters array exists&lt;br /&gt;parameters              MIME parameters array&lt;br /&gt;parts                         Array of objects describing each message part&lt;br /&gt;&lt;br /&gt;Cuando el mensaje es multipart “parts” es un vector donde cada elemento es un objeto con los siguientes datamembers:&lt;br /&gt;&lt;br /&gt;· type&lt;br /&gt;· encoding&lt;br /&gt;· subtype&lt;br /&gt;· description&lt;br /&gt;· lines&lt;br /&gt;· disposition&lt;br /&gt;&lt;br /&gt;Luego según el trasnfer encoding (ver tabla 3) se puede usar la función de decodificación apropiada&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Table 2. Primary body type&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;0                 text&lt;br /&gt;1                 multipart&lt;br /&gt;2                 message&lt;br /&gt;3                 application&lt;br /&gt;4                 audio&lt;br /&gt;5                 image&lt;br /&gt;6                 video&lt;br /&gt;7                 other&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Table 3. Transfer encodings&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;0                 7BIT&lt;br /&gt;1                 8BIT&lt;br /&gt;2                 BINARY&lt;br /&gt;3                 BASE64&lt;br /&gt;4                 QUOTED-PRINTABLE&lt;br /&gt;5                 OTHER&lt;br /&gt;&lt;br /&gt;Las funciones de decodificación provistas son:&lt;br /&gt;&lt;br /&gt;string=imap_base64(string) convierte de base 64 a 8 bits&lt;br /&gt;string=imap_8bit(string) convierte de 8 bits a quoted printable&lt;br /&gt;string=imap_utf7_decode(string) convierte de 7 bits a 8 bits&lt;br /&gt;string=imap_qprint(string) convierte de quoted printable a 8 bits&lt;br /&gt;string=imap_binary(string) convierte de 8 bits a base64&lt;br /&gt;&lt;br /&gt;El formato de salida “string” es 8 bits, si el formato de encoding es otro basta con usar la función apropiada.&lt;br /&gt;&lt;br /&gt;string=imap_fetchbody (mail_handler, int msg_number, string part_number )&lt;br /&gt;&lt;br /&gt;Recupera la parte indicada del body de un determinado mensaje. No realiza ningún tipo de decodificación.&lt;br /&gt;&lt;br /&gt;array= imap_headers (mail_handlers)&lt;br /&gt;&lt;br /&gt;Devuelve un vector de headers para el mailbox actual (cada header es un string y es un elemento del vector)&lt;br /&gt;&lt;br /&gt;object=imap_rfc822_parse_headers(string headers)&lt;br /&gt;&lt;br /&gt;Parsea un header de acuerdo a rfc822, devuelve un objeto con los siguientes data_members:&lt;br /&gt;&lt;br /&gt;· remail&lt;br /&gt;· date&lt;br /&gt;· Date&lt;br /&gt;· subject&lt;br /&gt;· Subject&lt;br /&gt;· in_reply_to&lt;br /&gt;· message_id&lt;br /&gt;· newsgroups&lt;br /&gt;· followup_to&lt;br /&gt;· references&lt;br /&gt;&lt;br /&gt;string imap_body (mail_handler, int msg_number)&lt;br /&gt;&lt;br /&gt;Devuelve el body de un determinado mensaje.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Envío de mail:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Enviar mail desde PHP es sencillo con la función:&lt;br /&gt;&lt;br /&gt;bool= mail (string to, string subject, string message [, string additional_headers])&lt;br /&gt;&lt;br /&gt;Ejemplo&lt;br /&gt;&lt;br /&gt;mail("rasmus@lerdorf.on.ca", "My Subject", "Line 1\nLine 2\nLine 3");&lt;br /&gt;&lt;br /&gt;Ejemplo 2. Envio de mail con encabezado.&lt;br /&gt;&lt;br /&gt;mail("nobody@aol.com", "the subject", $message,&lt;br /&gt;"From: webmaster@$SERVER_NAME\nReply-To: webmaster@$SERVER_NAME\nXMailer:&lt;br /&gt;PHP/" . phpversion());&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-1289285716282454601?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/1289285716282454601/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=1289285716282454601' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1289285716282454601'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/1289285716282454601'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2007/11/captulo-17-manejo-de-mail-en-php.html' title='Capítulo 17: Manejo de Mail en PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-4279215694997279255</id><published>2007-11-24T09:26:00.000-03:00</published><updated>2008-02-05T19:52:07.394-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Capítulo 18: Networking y FTP usando PHP</title><content type='html'>&lt;span style="font-weight: bold;"&gt;Funciones de FTP:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Uno de los problemas no solucionados por la mayoría de los lenguajes de scripting para la web es la transferencia de archivos entre diversos sites, usando NFS (Network file system) es posible crear zonas de un file-system que sean compartidas por más de un site, pero esto obliga a usar NFS, a tener una sobrecarga administrativa y además insertar varios problemas de seguridad delicados relacionados con NFS. El método más seguro y confiable para transferir archivos, PHP provee funciones nativas para usar FTP en forma directa desde un script php, las funciones más usadas son las siguientes:&lt;br /&gt;&lt;br /&gt;ftp_handler=ftp_connect(host);&lt;br /&gt;&lt;br /&gt;Ejemplo&lt;br /&gt;&lt;br /&gt;$ftp=ftp_connect(“100.100.100.100”);&lt;br /&gt;&lt;br /&gt;Si el puerto de FTP no es el default (21) se puede pasar como segundo parámetro de ftp_connect, la función devuelve un handler a ser usado por el resto de las funciones de FTP.&lt;br /&gt;Devuelve true/false segun el éxito o fracaso de la conexión.&lt;br /&gt;&lt;br /&gt;int=ftp_login(ftp_handler,string_user,string_password);&lt;br /&gt;&lt;br /&gt;Realiza un login a la conexión FTP indicada por el handler. (devuelve true/false según el éxito o fracaso del login)&lt;br /&gt;&lt;br /&gt;int=ftp_chdir(ftp_handler, string_directory);&lt;br /&gt;&lt;br /&gt;Cambia al directorio especificado como segundo parámetro dentro de la conexión ftp abierta para el ftp_handler pasado.Devuelve true/false&lt;br /&gt;&lt;br /&gt;int=ftp_get (ftp_handler, string_local_file, string_remote_file, int mode);&lt;br /&gt;&lt;br /&gt;Transfiere el archivo string_remote_file a la maquina donde corre el script creandolo con el path indicado en string_local_file, el modo debe ser una constante que puede ser FTP_BINARY o FTP_ASCII&lt;br /&gt;&lt;br /&gt;Ejemplo&lt;br /&gt;&lt;br /&gt;$ret=ftp_get($ftp,”/temp/cosa.dat”,”cosa.dat”,FTP_BINARY);&lt;br /&gt;&lt;br /&gt;Notar que no deben usarse comillas en el cuarto parámetro por tratarse de una constante y no de un string.&lt;br /&gt;&lt;br /&gt;int=ftp_fget (ftp_handler, file_handler, string_remote_file, int mode)&lt;br /&gt;&lt;br /&gt;Idem anterior pero el segundo parámetro es un handler a un archivo abierto con fopen en donde se guardaran los datos leídos desde la conexión ftp.&lt;br /&gt;&lt;br /&gt;int=ftp_put (ftp_handler, string_remote_file, string_local_file, int mode)&lt;br /&gt;&lt;br /&gt;Transfiere un archivo local indicado por string_local_file mediante la conexión ftp abierta creando un archivo de nombre string_remote_file.&lt;br /&gt;&lt;br /&gt;int=ftp_fput (ftp_handler, string_remote_file, file_handler, int mode)&lt;br /&gt;&lt;br /&gt;Idem anterior pero el archivo a trasnferir se indica por el file_handler de un archivo abierto con fopen.&lt;br /&gt;&lt;br /&gt;string=ftp_mkdir (ftp_handler, string_directory)&lt;br /&gt;&lt;br /&gt;Crea un directorio en la conexión ftp abierta, devuelve el nombre del directorio creado o falso si no pudo crearlo.&lt;br /&gt;&lt;br /&gt;int=ftp_rmdir (ftp_handler, string directory)&lt;br /&gt;&lt;br /&gt;Elimina el directorio indicado, devuelve true/false.&lt;br /&gt;&lt;br /&gt;int=ftp_cdup (ftp_handler)&lt;br /&gt;&lt;br /&gt;Cambia al directorio padre del actual.&lt;br /&gt;&lt;br /&gt;array=ftp_rawlist (ftp_handler, string_directory)&lt;br /&gt;&lt;br /&gt;Devuelve un vector con la lista de archivos presentes en el directorio indicado de acuerdo al comando FTP ftp_list, el resultado es un vector donde cada elemento del vector es una línea devuelta por ftp_list.&lt;br /&gt;&lt;br /&gt;int=ftp_size (ftp_handler, string_remote_file)&lt;br /&gt;&lt;br /&gt;Devuelve el tamaño del archivo indicado.&lt;br /&gt;&lt;br /&gt;ftp_quit(ftp_handler);&lt;br /&gt;&lt;br /&gt;Se desconecta de la conexión ftp realizada con ftp_connect.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Networking en PHP:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;PHP dispone de varias funciones de networking la más usada y la más flexible es fsockopen que permite conectarse a un socket en un host determinado por una dirección IP y un puerto, mediante esta funcion es posible conectarse a servidores HTPP, FTP, Telnet, IMAP, POP3 y otros protocolos.&lt;br /&gt;Es de destacar que la funcionalidad de Networking de PHP es como CLIENTE, PHP no puede crear un socket con nombre y hacer un “listen” de conexiones a dicho port por lo que no puede funcionar como servidor. La sintaxis de fsockopen es:&lt;br /&gt;&lt;br /&gt;file_handler=fsockopen (string_hostname, int port , int errno , string_errstr , double timeout)&lt;br /&gt;&lt;br /&gt;Los tres últimos parámetros son opcionales.&lt;br /&gt;Hostname es el nombre o dirección IP del host al cual conectarse.&lt;br /&gt;Port es el número de puerto al cual conectarse en el host.&lt;br /&gt;errno debe ser una referencia a una variable en donde se guarda el número de error en caso de no poder conectarse.&lt;br /&gt;errstr es una referencia a una variable en donde se guarda un mensaje de error en caso de no poder conectarse&lt;br /&gt;El timeout es el tiempo máximo a esperar por la conexión en segundos.&lt;br /&gt;Devuelve un file handler o false según pueda o no conectarse. El file hanlder devuelto puede luego usarse como un archivo normal usando fgets, fputs, feof, fclose, etc...&lt;br /&gt;&lt;br /&gt;Ejemplo:&lt;br /&gt;&lt;br /&gt;$fp = fsockopen ("www.php.net", 80, &amp;amp;$errno, &amp;amp;$errstr, 30);&lt;br /&gt;if (!$fp) {&lt;br /&gt;echo "$errstr ($errno)&lt;br /&gt;\n";&lt;br /&gt;} else {&lt;br /&gt;fputs ($fp, "GET / HTTP/1.0\n\n");&lt;br /&gt;while (!feof($fp)) {&lt;br /&gt;echo fgets ($fp,128);&lt;br /&gt;}&lt;br /&gt;fclose ($fp);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;En este ejemplo abrimos el puerto 80 (Protocolo HTTP) de un host (www.php.net )&lt;br /&gt;Luego ponemos en el socket un request de HTTP y entramos en un loop recuperando el contenido que devuelve el server. Es un mini simulador de browser HTTP.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-4279215694997279255?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/4279215694997279255/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=4279215694997279255' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4279215694997279255'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/4279215694997279255'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2007/11/captulo-18-networking-y-ftp-usando-php.html' title='Capítulo 18: Networking y FTP usando PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1246969963583076690.post-7100350092515020872</id><published>2007-11-24T09:07:00.000-03:00</published><updated>2008-02-05T19:52:36.811-02:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='General'/><title type='text'>Capítulo 19: Funciones adicionales de PHP</title><content type='html'>&lt;div style="text-align: justify;"&gt;&lt;span style="font-weight: bold;"&gt;Persistencia:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Una de las características importantes en lenguajes orientados a objetos o lenguajes de scripting modernos es la persistencia, un objeto persistente es aquel que puede almacenarse en un medio de almacenamiento secundario (un archivo o una base de datos) para luego recuperarlo. PHP provee de dos funciones que permiten realizar esto serializando y des-serializando variables de PHP.&lt;br /&gt;&lt;br /&gt;string=serialize(var);&lt;br /&gt;&lt;br /&gt;Recibe cualquier variable de PHP incluso un objeto y devuelve un string que es una representación de la variable, dicho string puede almacenarse en un archivo o una base de datos para lograr persistencia.&lt;br /&gt;&lt;br /&gt;var=unserialize(string);&lt;br /&gt;&lt;br /&gt;Recibe un string que es la serialización de una variable, des-serializa y asigna a la variable pasada. Para desserializar un objeto es necesario que el script que usa unserialize disponga de la definición de la clase.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Funciones de hashing y encriptación:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;string=md5(string)&lt;br /&gt;&lt;br /&gt;Devuelve un string de 32 bytes que es un “digest” del string original, es decir aplica al string original una función de hashing unidireccional.&lt;br /&gt;&lt;br /&gt;string=crypt(string)&lt;br /&gt;&lt;br /&gt;Encripta un string usando el método unidireccional de Unix, usado por ejemplo para almacenar passwords, el string devuelto es de extensión variable. No se puede desencriptar.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Generación de identificadores únicos:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;string=uniqid(string_base);&lt;br /&gt;&lt;br /&gt;Construye un identificador único tomando como base un string pasado, por ejemplo para generar identificadores únicos de 32 bits aleatorios se usa:&lt;br /&gt;&lt;br /&gt;$better_token = md5 (uniqid (rand()));&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Ejecución de codigo PHP:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;eval(string_codigo);&lt;br /&gt;&lt;br /&gt;Evalúa el string como si fuera código PHP y lo ejecuta.&lt;br /&gt;&lt;br /&gt;Ejemplo:&lt;br /&gt;&lt;br /&gt;eval(“print(\”hola\”)”);&lt;br /&gt;&lt;br /&gt;Imprime hola como si se ejecutara la instrucción print, la función eval es útil en varios casos por ejemplo para guardar código PHP en un archivo o base de datos y luego recuperarlo y ejecutarlo dinámicamente (por ejemplo para que usuarios de un web site suban sus propios scripts PHP) o bien usando funciones de parsing XML para insertar en XML processing-instructions de tipo  y luego en el script php que parsea el XML ejecutar el código php con eval.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Control del script:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;sleep(segundos);&lt;br /&gt;&lt;br /&gt;Hace una pause de la cantidad de segundos indicados.&lt;br /&gt;&lt;br /&gt;die(string);&lt;br /&gt;&lt;br /&gt;Termina la ejecución del script imprimiendo el string pasado.&lt;br /&gt;&lt;br /&gt;exit();&lt;br /&gt;&lt;br /&gt;Finaliza la ejecución del script.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Manejo de URLs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;string=base64_decode(string);&lt;br /&gt;&lt;br /&gt;Decodifica un string encodeado en base64.&lt;br /&gt;&lt;br /&gt;string=base64_encode(string);&lt;br /&gt;&lt;br /&gt;Codifica un string a base64.&lt;br /&gt;&lt;br /&gt;string=urlencode(string);&lt;br /&gt;&lt;br /&gt;Codifica un string de acuerdo a RFC1738 es decir reemplaza todos los caracteres que no sean alfanuméricos o “_”,”.“,”-“ por un signo “%” seguido de una representación hexadecimal del caracter de acuerdo a RFC1738, los espacios en blanco se codifican como %20 por ejemplo. Este formato es “seguro” para pasarlo como query_string en un URL&lt;br /&gt;&lt;br /&gt;Ejemplo tipico:&lt;br /&gt;&lt;br /&gt;$ulr_string=urlencode($string_raro);&lt;br /&gt;print(“”);&lt;br /&gt;etc...&lt;br /&gt;&lt;br /&gt;string=urldecode(string);&lt;br /&gt;&lt;br /&gt;Decodifica un string encodeado con urlencode.&lt;br /&gt;&lt;br /&gt;array=parse_url(string_url);&lt;br /&gt;&lt;br /&gt;Recibe un string representando una URL y devuelve un vector asociativo de donde pueden recuperarse las sigiuientes claves: "scheme", "host", "port", "path", "query"&lt;br /&gt;&lt;br /&gt;Ejemplo:&lt;br /&gt;&lt;br /&gt;http://www.yahoo.com:8080/pruebas/coso.php?hola=5&amp;amp;cosa=6&lt;br /&gt;&lt;br /&gt;Scheme : http&lt;br /&gt;Host : www.yahoo.com&lt;br /&gt;Port : 8080&lt;br /&gt;Path : /pruebas/coso.php&lt;br /&gt;Query : hola=5&amp;amp;cosa=6&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1246969963583076690-7100350092515020872?l=mfw-php.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mfw-php.blogspot.com/feeds/7100350092515020872/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1246969963583076690&amp;postID=7100350092515020872' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7100350092515020872'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1246969963583076690/posts/default/7100350092515020872'/><link rel='alternate' type='text/html' href='http://mfw-php.blogspot.com/2007/11/captulo-19-funciones-adicionales-de-php.html' title='Capítulo 19: Funciones adicionales de PHP'/><author><name>Fabián Pérez</name><uri>http://www.blogger.com/profile/11587678441824841623</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://ar.geocities.com/fabianperez2003/img/Foto10.jpg'/></author><thr:total>0</thr:total></entry></feed>
