Difference between revisions of "PHP Basics"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
Line 2: Line 2:
  
 
PHP is a server side scripting language, which is run on the server before the page is served to the client. Essentially it dynamically creates pages on the fly. It can be written on it's own our within normal standard HTML etc. It must be stored on a running webserver and you can only access it via it's URL in a browser. The page the client will receive will have all of the server side elements replaced with the output of the code. If your viewed source you would only see standard HTML and text.
 
PHP is a server side scripting language, which is run on the server before the page is served to the client. Essentially it dynamically creates pages on the fly. It can be written on it's own our within normal standard HTML etc. It must be stored on a running webserver and you can only access it via it's URL in a browser. The page the client will receive will have all of the server side elements replaced with the output of the code. If your viewed source you would only see standard HTML and text.
 +
 +
==PHP Tags==
 +
 +
PHP code must be contained within PHP tags, these tags can be placed anywhere in the page because they are all run before the page is served to the client.
 +
 +
<syntaxhighlight lang="php" line>
 +
<?php // the opening PHP tag
 +
// your PHP code
 +
?> // the closing PHP tag
 +
</syntaxhighlight>
  
 
== Creating a Hello World in PHP ==
 
== Creating a Hello World in PHP ==
 
<syntaxhighlight lang="php" line>
 
<syntaxhighlight lang="php" line>
echo "hello world";
+
<?php echo "hello world"; ?>
 
//Output:
 
//Output:
 
//hello world
 
//hello world
Line 12: Line 22:
 
echo is used to write text to the page, you could also echo html code or variables:
 
echo is used to write text to the page, you could also echo html code or variables:
 
<syntaxhighlight lang="php" line>
 
<syntaxhighlight lang="php" line>
echo "<p>Hello World<br>Hola Mundo</p>";
+
<?php echo "<p>Hello World<br>Hola Mundo</p>"; ?>
 
//Output:
 
//Output:
 
//Hello World
 
//Hello World
 
//Hola Mundo
 
//Hola Mundo
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 23:27, 16 December 2016

This section needs expansion.
You can help by adding to it.

PHP is a server side scripting language, which is run on the server before the page is served to the client. Essentially it dynamically creates pages on the fly. It can be written on it's own our within normal standard HTML etc. It must be stored on a running webserver and you can only access it via it's URL in a browser. The page the client will receive will have all of the server side elements replaced with the output of the code. If your viewed source you would only see standard HTML and text.

PHP Tags

PHP code must be contained within PHP tags, these tags can be placed anywhere in the page because they are all run before the page is served to the client.

1 <?php // the opening PHP tag
2 // your PHP code
3 ?> // the closing PHP tag

Creating a Hello World in PHP

1 <?php echo "hello world"; ?>
2 //Output:
3 //hello world

echo is used to write text to the page, you could also echo html code or variables:

1 <?php echo "<p>Hello World<br>Hola Mundo</p>"; ?>
2 //Output:
3 //Hello World
4 //Hola Mundo