Martin Francis

DSA PHP Introduction

PHP scripting

Introduction

php commands are typically embedded in an HTML page which is saved with a suffix of .php. The webserver Windows IIS or Apache should be configured to pass such files through the PHP interpreter. Output will be returned to the requestor.

This script shows some of the basics of PHP - you need to read the script alongside the output from the script to see how each structure works.

Sample output from this PHP script

PHP has evolved to be a complex language which will take some time and effort to learn in all its glory. This example aims to show you you the most commonly used parts of PHP, and should be enough to read simple scripts.

Handling access to to Form data and linking to dtabases will be in a further worksheet

Sections of php script start with <?php and are terminated by ?>

They can be just snippets : Time is
Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 68

Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 68
08:01 . or whole programs

Fred

Printing

222222

String

PHP executes on the server

$s was developed by $t

PHP was developed by Rasmus Lerdorf

PHP was developed by Rasmus Lerdorf

Numbers

Bases 10: 255 16: 255 8: 255

c=1 d=7.2

Logic

FalseFalseFalseFalseTrueTrueTrue

Arrays

Array ( [0] => 1 [5] => 12 [6] => 3 )

Control Structures

A is FOUR

B is not FOUR

1 squared is 1 3 squared is 9 5 squared is 25 7 squared is 49 9 squared is 81

PHP was created by Rasmus Lerdorf

COBOL was created by Grace Hopper

Number functions

  • Square root of 2 : 1.41421356237
  • Rounded to two places : 1.41
  • a Random number between 1 and 10 : 7

String functions

  • String : PHP provides a large library of functions
  • length is 43
  • first two characters P
  • last three characters ns
  • position of "large" 16
  • uppercase the string PHP PROVIDES A LARGE LIBRARY OF FUNCTIONS
  • lowercase the string php provides a large library of functions
  • trim whitespace from both ends PHP provides a large library of functions
  • base64 encoded IFBIUCBwcm92aWRlcyBhIGxhcmdlIGxpYnJhcnkgb2YgZnVuY3Rpb25zIA==
  • base64 decoded PHP provides a large library of functions

Date functions


    Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 282

    Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 282
  • Current Time : 08:01
    Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 283

    Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 283
  • Day of week: Wednesday
    Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 284

    Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 284
  • Date : 25/04/18
  • Date info
    Warning: getdate() [function.getdate]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 285

    Warning: getdate() [function.getdate]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 285
    Array ( [seconds] => 22 [minutes] => 1 [hours] => 8 [mday] => 25 [wday] => 3 [mon] => 4 [year] => 2018 [yday] => 114 [weekday] => Wednesday [month] => April [0] => 1524639682 )

Arrays

  • array dump : Array ( [0] => Sunday [1] => Monday [2] => Tuesday [3] => Wednesday [4] => Thursday [5] => Friday [6] => Saturday )
  • length is 7
  • array joined with : Sunday:Monday:Tuesday:Wednesday:Thursday:Friday:Saturday
    Warning: split() [function.split]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 298

    Deprecated: Function split() is deprecated in /home/martinfr/public_html/dsa_php_intro.php on line 298
  • string separated by : split to array : Array ( [0] => Sunday [1] => Monday [2] => Tuesday [3] => Wednesday [4] => Thursday [5] => Friday [6] => Saturday )
    Warning: getdate() [function.getdate]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 300

    Warning: getdate() [function.getdate]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in /home/martinfr/public_html/dsa_php_intro.php on line 300
  • Weekday today : Wednesday

User Defined Functions

END the info END
.. END the info END ..