Difference between revisions of "PHP"

From Conservapedia
Jump to: navigation, search
(External links)
m (reorder closing sections)
(18 intermediate revisions by 9 users not shown)
Line 1: Line 1:
'''PHP''' is a [[server]]-side scripting language for creating interactive [[web page]]s. The acronym ''PHP'' derives from Personal Home Page, but now it is defined as "PHP: Hypertext Pre-Processor" (it means "something to handle data before it becomes HTML" <ref> [http://www.htmlite.com/php001.php] </ref> ). Unlike [[HTML]], JavaScript and others, PHP is a Server-Side scripting language. It most always is processed into HTML for use in a web page.
+
'''PHP''' is a server-side scripting language for creating interactive [[web page]]s. The acronym ''PHP'' derives from Personal Home Page, but is now defined as "PHP: Hypertext Pre-Processor" (it means "something to handle data before it becomes HTML"<ref>[http://www.htmlite.com/php001.php HTMLite PHP Tutorial]</ref> ). Unlike [[HTML]], JavaScript and others, PHP is a Server-Side scripting language. It most always is processed into HTML for use in a web page.
  
 
PHP is one of the most popular scripting languages in the Open Source world, which is often used together with [[Apache]] on [[Linux]] or on other paid platforms such as Microsoft [[IIS]] on [[Windows]].
 
PHP is one of the most popular scripting languages in the Open Source world, which is often used together with [[Apache]] on [[Linux]] or on other paid platforms such as Microsoft [[IIS]] on [[Windows]].
  
The PHP syntax is very similar to Perl and C. <ref name="w3">[http://www.w3schools.com/php/default.asp PHP Tutorial from W3Schools]</ref>
+
The PHP syntax is very similar to Perl and C.<ref name="w3">[http://www.w3schools.com/php/default.asp PHP Tutorial from W3Schools]</ref>
  
 
PHP is an ''interpreted language'' (like Perl) and not a ''compiled'' one (like [[Java]] or [[C]]).  
 
PHP is an ''interpreted language'' (like Perl) and not a ''compiled'' one (like [[Java]] or [[C]]).  
Line 12: Line 12:
  
 
Important note:
 
Important note:
* single quoted strings don't recognize special character codes like \n <ref name="sitepoint">[http://www.sitepoint.com/article/advanced-email-php/3/ Advanced PHP from Sitepoint]</ref>
+
* single quoted strings don't recognize most special character codes like \n <ref name="sitepoint">[http://www.sitepoint.com/article/advanced-email-php/3/ Advanced PHP from Sitepoint]</ref> and don't expand variables, however they do recognize \' and \\ <ref name="phpstrings">PHP: [http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.single Strings]</ref>
  
 
===Concatenation ===
 
===Concatenation ===
Line 20: Line 20:
 
Example:
 
Example:
  
<code>
+
{{QuoteBox|<nowiki>$first = "car";</nowiki><br />
  $first = "car";
+
<nowiki>$second = "nation";</nowiki><br />
  $second = "nation";
+
<nowiki>$product= $first . $second;</nowiki><br />
  $product= $first . $second;
+
<br />
+
<nowiki>// Equivalent to:</nowiki><br />
  // Equivalent to:
+
<nowiki>$product= "carnation"</nowiki>}}
  $product= "carnation"
+
</code>
+
  
PHP recognizes variable names within strings, which are enclosed in double quotes.
+
PHP recognizes variable names within strings, which are enclosed in double quotes. Since all variables begin with a dollar sign, it is easy to embed one string inside another. This is the preferred way to create HTML output.
Since all variables begin with a dollar sign, it is easy to embed one string inside another. This is the preferred way to create HTML output.
+
  
 
For example:
 
For example:
  
<code>
+
{{QuoteBox|<nowiki>$first = "John";</nowiki><br />
    $first = "John";
+
<nowiki>$middle = "Quincy"</nowiki><br />
    $middle = "Quincy"
+
<nowiki>$last = "Adams";</nowiki><br />
    $last = "Adams";
+
     <br />
      
+
<nowiki>// Show full name, in bold format</nowiki><br />
    // Show full name, in bold format
+
<nowiki>echo "<B>$first $middle $last</B>";</nowiki>}}
    echo <nowiki>"<B>$first $middle $last</B>";</nowiki>
+
</code>
+
  
 
This outputs <nowiki>"<B>John Quincy Adams</B>"</nowiki> to the HTML page.
 
This outputs <nowiki>"<B>John Quincy Adams</B>"</nowiki> to the HTML page.
Line 54: Line 49:
 
*MS-SQL 2000
 
*MS-SQL 2000
 
*Oracle
 
*Oracle
 +
*SQLite
  
 
and many others.
 
and many others.
 +
 +
===PHP and MySQL===
 +
 +
PHP and MySQL are both [[free software]], and they work together well for making database-backed websites.
 +
 +
Methods for PHP to access MySQL databases include mysqli and PDOs.
  
 
==Books==
 
==Books==
 
*''How to Do Everything with PHP & MySQL'', Vikram Vaswani (McGraw-Hill, 2005)
 
*''How to Do Everything with PHP & MySQL'', Vikram Vaswani (McGraw-Hill, 2005)
  
==External links==
+
==See also==
*[http://www.w3schools.com/php/default.asp PHP Tutorial] - W3 Schools
+
* [[Embed PHP into HTML]]
*[http://php.net PHP.net] - Offical PHP Website.
+
[[category:information technology]]
+
[[Category:Scripting Languages]]
+
  
 
==References==
 
==References==
 
<references/>
 
<references/>
 +
 +
==External links==
 +
*[http://php.net PHP.net] - Official PHP Website.
 +
 +
[[Category:Information Technology]]
 +
[[Category:Scripting Languages]]
 +
[[Category:Programming Languages]]

Revision as of 04:55, February 2, 2017

PHP is a server-side scripting language for creating interactive web pages. The acronym PHP derives from Personal Home Page, but is now defined as "PHP: Hypertext Pre-Processor" (it means "something to handle data before it becomes HTML"[1] ). Unlike HTML, JavaScript and others, PHP is a Server-Side scripting language. It most always is processed into HTML for use in a web page.

PHP is one of the most popular scripting languages in the Open Source world, which is often used together with Apache on Linux or on other paid platforms such as Microsoft IIS on Windows.

The PHP syntax is very similar to Perl and C.[2]

PHP is an interpreted language (like Perl) and not a compiled one (like Java or C).

Strings

Strings can be placed in single quotes or double quotes; this differs from Java, where single quotes are used only to enclose one single character rather than a string.

Important note:

  • single quoted strings don't recognize most special character codes like \n [3] and don't expand variables, however they do recognize \' and \\ [4]

Concatenation

The string concatenation operator is the period (or full stop). This is a major difference from many other programming languages, which use a plus sign or ampersand.

Example:

$first = "car";

$second = "nation";
$product= $first . $second;

// Equivalent to:

$product= "carnation"

PHP recognizes variable names within strings, which are enclosed in double quotes. Since all variables begin with a dollar sign, it is easy to embed one string inside another. This is the preferred way to create HTML output.

For example:

$first = "John";

$middle = "Quincy"
$last = "Adams";

// Show full name, in bold format

echo "<B>$first $middle $last</B>";

This outputs "<B>John Quincy Adams</B>" to the HTML page.

Databases

PHP is compatible with multiple databases, MySQL being the most popular. They go together so well that it's tempting to think of PHP as primarily middleware to link MySQL on the back end to HTML on the front end.

Overall, PHP is compatible with:

  • MySQL
  • PostgreSQL
  • MS-SQL 2000
  • Oracle
  • SQLite

and many others.

PHP and MySQL

PHP and MySQL are both free software, and they work together well for making database-backed websites.

Methods for PHP to access MySQL databases include mysqli and PDOs.

Books

  • How to Do Everything with PHP & MySQL, Vikram Vaswani (McGraw-Hill, 2005)

See also

References

  1. HTMLite PHP Tutorial
  2. PHP Tutorial from W3Schools
  3. Advanced PHP from Sitepoint
  4. PHP: Strings

External links