PHP

Heres a few PHP tips from:

https://learnable.com/books/jump-start-php/

First off install xampp as described in the following post:

http://goldnuggetdesigns.co.uk/2014/07/24/create-wordpress-theme/

Once installed go to (this won’t eed to be 8080 if you didn t need to change it):

http://localhost:8080/xampp/

Click on phpinfo()

Look fo Loaded Configuration File which will show you where the php.ini file is.

i.e.
C:xamppphpphp.ini

The php.ini file contains a large amount of settings, some of which you may never need to change. However, there are a few which can be changed to help tailor PHP to suit your development style and environment

See the folllowing article:
http://www.sitepoint.com/a-tour-of-php-ini/

In the httdocs add a folder called My_Project and add a file called index.php

Using a text editor such as Notepad++ in the index.php:

 

To see this work go to:

http://localhost:8080/my_project/index.php

  • <?php : This is called the opening tag. It tells your server that the code that follows is intended to be interpreted as PHP, and that the server should use the PHP engine to render the code. This tag must be entered every time you want to use PHP code in your file.
  • echo "Hello World"; : echo is a basic PHP construct which tells PHP that what follows the echo command is something you want to appear in the browser. Quotation marks are added around the text you want to display on screen. Also, you add the important semicolon afterward which signals that your echo statement is finished.
  • ?> : This is the closing tag for PHP and tells the server to stop rendering PHP code. The closing tag is not always used. Leaving the code “unclosed” can prevent unintended content from being sent to the browser. Skipping the closing tag when you don’t need it can avoid problems which may crop up as you start writing more complex PHP code. Further on in this book you’ll see code that doesn’t have a closing PHP tag. This tag has been omitted on purpose.

Use semicolons so that php knows where a command ends.

HTML and PHP can be combines as follows:

<!DOCTYPE html>
<html>
  <head>
    <title>PHP and HTML working together</title>
  </head>
  <body>
    <h1><?php echo 'This is a H1 tag with PHP data'; ?></h1>
    <p><?php echo 'This is a P tag with PHP data also'; ?></p>
  </body>
</html>

PHP Variables:

A variable is where bits of information (data) can be stored in the computer memory. Data can be assigned to a variable and can be used throughout your script.

Variables have to start with $ and can be letters, words and underscores. It is good practice to use meaningful names and use camelCase - $myvar
So an example:

<!DOCTYPE html>
<html>
 <head>
 <title>PHP and HTML working together</title>
 </head>
 <body>
 <h1><?php $testVar = "This is a test"; echo $testVar; ?></h1>
 <p><?php echo 'This is a P tag with PHP data also'; ?></p>
 </body>
</html>

Here are a few examples of data:

<?php
$myVar = 0;                          // Integer
$myVar = 3.14;                       // Float
$myVar = "Year to Date";             // String
$myVar = true;                       // Boolean
$myVar = array(250, 300, 325, 475);  // Array  

Here are the different variable types:

  • Integer – Whole numbers. These can be either positive or negative.
  • Float – Numbers with decimal places. These can also be either positive or negative.
  • String – A mixture of letters, numbers, and symbols. Strings are surrounded by quotes.
  • Boolean – One of two values: true or false. The value must not have any quotes as this would turn it into a string.
  • Array – A multi-level storage type, similar to a table.
Here are a few good articles about variables:

http://www.php.net/manual/en/language.variables.basics.php

http://www.sitepoint.com/variables/