We are still actively working on the spam issue.

Difference between revisions of "PHP"

From InstallGentoo Wiki
Jump to: navigation, search
m
Line 1: Line 1:
PHP is a server-side programming language that is very popular and [http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ often frowned upon]. The acronym PHP was originally Personal Homepage to which later it changed its name to the more accurate Hypertext Pre-Processor. It uses a C style syntax and even a lot basic C functions.  
+
'''PHP''' (PHP Hypertext Preprocessor) is a server-side programming language that is very popular and [http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ often frowned upon]. The acronym PHP was originally Personal Homepage to which later it changed its name to the more accurate Hypertext Pre-Processor. It uses a C style syntax and even a lot basic C functions.  
 
==Examples==
 
==Examples==
 
PHP is written inline with HTML documents, making it ideal for people who have experience with designing websites with HTML/CSS and want to create a more dynamic web experience. PHP is processed by the server before it is rendered in the browser.
 
PHP is written inline with HTML documents, making it ideal for people who have experience with designing websites with HTML/CSS and want to create a more dynamic web experience. PHP is processed by the server before it is rendered in the browser.
Line 8: Line 8:
  
 
===Hello World!===
 
===Hello World!===
     <?php echo "Hello world!"; ?>
+
     <span style="color:purple;"><?php</span>
 +
        <span style="color: blue;">echo</span> "<span style="color:green;">Hello world!</span>";
 +
    <span style="color:purple;">?></span>
  
If you put this code into a file and give it a ''.php'' extension, it will render plain text to the web browser. As you can see every piece of PHP must be opened and closed with the PHP html tags.
+
If you put this code into a file and give it a ''.php'' extension, it will render plain text to the web browser. If you embed PHP code in an HTML document, you must include the closing ?> tag, but if you have a pure PHP file the closing tag can and should be omitted (prevents extra newlines from being erroneously added and other errata; see [https://stackoverflow.com/questions/4410704/why-would-one-omit-the-close-tag]).
  
 
===Date===
 
===Date===
     <?php
+
     <span style="color:purple;"><?php</span>
         // variable declaration
+
         <span style="color: gray; font-style: italic;">// variable declaration</span>
         $date = date("Y/m/d");
+
         <span style="color: orange;">$date</span> = <span style="color: brown;">date</span>("<span style="color: green;">Y/m/d</span>");
 
      
 
      
         // using the variable with the echo function
+
         <span style="color: gray; font-style: italic;">// using the variable with the echo function</span>
         echo $date;
+
         <span style="color: blue;">echo</span> <span style="color: orange;">$date</span>;
    ?>
+
 
 
[http://ca1.php.net/manual/en/function.date.php The Date function] is a great tool to show how PHP generates dynamic content. The above format displays the full year, the month and day all in numbers like so: 1999/02/16.
 
[http://ca1.php.net/manual/en/function.date.php The Date function] is a great tool to show how PHP generates dynamic content. The above format displays the full year, the month and day all in numbers like so: 1999/02/16.
  
Line 27: Line 29:
 
====Apache====
 
====Apache====
 
On a Debian based distribution, you must install the Apache webserver, the PHP module and PHP itself.
 
On a Debian based distribution, you must install the Apache webserver, the PHP module and PHP itself.
     sudo apt-get install apache2 libapache2-mod-php5 php5
+
     $ sudo apt-get install apache2 libapache2-mod-php5 php5
 
====Nginx====
 
====Nginx====
 
Nginx requires you to have php5-fpm or php5-cgi installed and configured. This will show you how to install and configure php5-fpm with nginx.
 
Nginx requires you to have php5-fpm or php5-cgi installed and configured. This will show you how to install and configure php5-fpm with nginx.

Revision as of 01:13, 29 January 2014

PHP (PHP Hypertext Preprocessor) is a server-side programming language that is very popular and often frowned upon. The acronym PHP was originally Personal Homepage to which later it changed its name to the more accurate Hypertext Pre-Processor. It uses a C style syntax and even a lot basic C functions.

Examples

PHP is written inline with HTML documents, making it ideal for people who have experience with designing websites with HTML/CSS and want to create a more dynamic web experience. PHP is processed by the server before it is rendered in the browser.

All of the examples here assume that you have a rudimentary understanding of HTML and have webserver software installed on your system, or access to a webserver with PHP.

The PHP documentation is a valuable resource that should always be open in a seperate tab when you're developing PHP projects.

Hello World!

   <?php
       echo "Hello world!";
   ?>

If you put this code into a file and give it a .php extension, it will render plain text to the web browser. If you embed PHP code in an HTML document, you must include the closing ?> tag, but if you have a pure PHP file the closing tag can and should be omitted (prevents extra newlines from being erroneously added and other errata; see [1]).

Date

   <?php
       // variable declaration
       $date = date("Y/m/d");
   
       // using the variable with the echo function
       echo $date;

The Date function is a great tool to show how PHP generates dynamic content. The above format displays the full year, the month and day all in numbers like so: 1999/02/16.

Set Up

Linux/BSD

Most package managers have a current version (5.x) of PHP being maintained. Server software needs specific tools to allow PHP to be executed on the system.

Apache

On a Debian based distribution, you must install the Apache webserver, the PHP module and PHP itself.

   $ sudo apt-get install apache2 libapache2-mod-php5 php5

Nginx

Nginx requires you to have php5-fpm or php5-cgi installed and configured. This will show you how to install and configure php5-fpm with nginx.

Windows

You could, if you're silly, download WAMPserver but that is generally not the best move. However, if you were serious about PHP development you would use a dedicated server.

Software