Edgar Huckert: PHP

Some basic tests in PHP

As I forget frequently the basic features of PHP I have written a standalone test program that contains the most essential features:

Note that the multibyte functions contained in this test program must be installed separately (sudo apt install php7.4-mbstring).

I had to name this file "PHPTest.txt" instead of "PHPTest.php". When having the extension ".php" it would be executed directly as soon as the link is activated - you would only see the results (outputs) of the program, not the program source text. You can run this on the command line by saying:
          php PHPTest.php

A PHP client (I used PHP client V7.4) must be installed as this program is used outside the WEB(HTML context.

PHP is great for embedding in HTML pages. I use it frequently for entering values in my MYSQL databases, for submitting SQL queries and for getting results from the databases on my WEB server - but this is not shown in this sample file.

Working with files in PHP

File IO in PHP is very similar to file IO in the standard C library. I have written here a small PHP program that shows the basic functions for file handling. The file reads a simple ASCII text file (the content is not important) and writes out MD5-encrypted lines. As in the standard C library you will find here built-in functions like:

The program also demonstrates how user defined functions and exceptions can be used in PHP. This program is designed for usage by a PHP client (not for inclusion in a HTML page). It runs on the command line. Here again the extension of the source file should be changed to ".php" before executing the program.

WEB Pages and database access

Many simple database applications in the WEB context can be designed as a two phase process:

To demonstrate web access and data base access (in my case MySQL) I have prepared two files:

Here is a screen dump for the data entry form voc_entry1.html:

The PHP script voc_entry2.php is called in the FORM METHOD... tag in HTML form voc_entry1.html. The PHP script follows these steps: The field contents I need to fill table vocabulary are in the associative array _POST[] - a standard mechanism offered by PHP.

Here is the very simple SQL script that creates the table I use in this sample:

CREATE TABLE `vocabulary` (
  `word1` varchar(40) DEFAULT NULL,
  `translation` varchar(40) DEFAULT NULL,
  `language` varchar(3) NULL,
  `comment` varchar(40) DEFAULT NULL,
  `id` int(11) DEFAULT NULL


Copyright for all images, texts and software on this page: Dr. E. Huckert

If you want to contact me: this is my
mail address