What is PHP? | Here are the different ways to store data in PHP 5.0

in #uganda6 years ago (edited)

advantages-of-php.jpg

Php began in 1994 as a series of scripts called PHP/FI (Personal Home Page / Forms interpreter). Over the years ,Php grew into something more serious. In 1997, a second version of the system came out with additional functionality.
In late 1998, Php 3.0 was released, leading to major rewrite of code. The goal was to support progressively broader and more complex applications on the web. In early 2000, version 4.0 was released. Based on a new language engine called Zend engine, this version had much better performance and increased code modularity. By late 2004, the much involved version 5.0 was released (this is the one in current use today). It includes many new features, such as new language constructs, broader web server support, sessions, and additional third party extensions. Among the new language features was a new introduced in Php 5.0 was a significantly improved and expanded object-oriented programming model, which I will be using extensively in my future posts. Somewhere along the way, Php ceased to to refer to "Personal Home Page" and came to mean "PHP Hypertext Preprocessor", a so called recursive acronym.
Php is a remarkably productive language which you can sit down and crank out large amounts of code in a short period of time, which is one of my main objectives in my forth coming posts to help people in the steemit community to be able to embrace programming and gaining its skills through Php and which this productivity is what drew me to it a few years back.

The one possible "fly in the ointment" is that the language can be quickly compared to other programming languages, like C++, java, and many others.

what is Php?


what-is-php.jpeg

Php is an interpreted scripting language, meaning that the language engine simply runs the scripts you have written with no necessary intermediate steps to compile or convert them into binary formats. Most of the Php files that you will create will go in the same place as your HTML content files. Files containing PHP scripts will typically have the .php extension.
When the web server receives a request for an appropriate name file, it passes this to the PHP engine, which then processes the file one line at a time. For limes that do not contain Php code (typically, lines containing HTML markup), the server emits them untouched and executes any PHP script code ad it is seen.

Mixing Php and HTML.

There is nothing that requires large blocks of PHP code when writing PHP and HTML: You are completely free to mix the markup and scripts as much as you wish.

How to store data.

At some point, you will want to hold on to and manipulate data of varying sorts. You can do this in PHP using variables. Variables are a place to store data for later use. They are valid for the duration of the currently executing script.

PHP is different from many other languages, in that variables do not need to be declared before they are used, you simply assign it a value. Variable names in PHP are represented by a dollar sign ($) followed by an identifier that begins with either a letter or an underscore, which in turn can be followed by any number of underscores, numbers, or letters.

Included in the set of letters permitted for variable names are some extended characters, such as accented Latin letters. However, other extended characters such as accented many Chinese characters seen in Japanese and Chinese alphabets, are not permitted.
Capture1.PNG

Entering basic types in PHP.

If you have been a programmer of some of kind of language other than PHP, you will find working with types in PHP a slightly different and occasionally quirky experience. PHP is a richly typed language, where each piece of data has a type associated with it, but variables are not declared as having a particular type hence tr language engine determines the type to use based on a set of rules.

1. Numbers.

There are two basic types of numbers in the language: integer(int) and float(float). While many languages distinguish between single and double-precision floating-point digits of precision. PHP does, however, support the keyword double in addition to float for compatibility.

Integers are specified in code in octal(base-8), decimal(base-10), or hexadecimal(base-16) notations.
Here is a sample to clarify:
Capture2.PNG
Integer precision varies largely by the underlying operating system, but 32 bits is common. There are no unsigned integers in PHP, so maximum value for an integer is typically larger than 2 billion. However, unlike other languages that overflow large positive integers into large negative integers, PHP actually overflows integers to floating point numbers.
Capture3.PNG
The output of the script is:

int(2147483647) float(2147483648)

In the above code snippet, there is the var_dump function, a powerful debugging tool used to seesee both the type and and value of the variable in PHP.
Floating point variables can be input in a few different ways:
Capture4.PNG
One caution with floating point numbers is that they are only approximate values. Because of their limited precision, they are very close to the intended value but are not always the value you would like.

For example the value 2.5 will always be represented internally as 2.4999999999, or something similar. Thus the following code will always prove problematic:
Capture5.PNG
Code snippets such as these will always print out "what???", depending on the exact implementation of floating point numbers. I recommend that you avoid comparing specific floating-point values. Instead you should round them off to the nearest integer value using round, or compare them against a range of values.

2. Strings.

A string is a sequence of values and in PHP, the string characters are 8-bit values. This is convenient for many Western languages but proves a bit problematic when trying to work with systems using more complicated alphabets, such as Chinese!

There are three ways to specify a string valuable.

Single Quoted.

Single-quoted strings are sequences of characters that begin and end with a single quote(').
Capture6.PNG
To include a single quote within a string, you simply put a backslash in front of it. This is called escaping the character.
Capture7.PNG

Double Quoted.

Double-quoted strings are similar to single-quoted strings, except that the PHP language processor actually dissects them to find and replace special escape sequences and variables.
Capture8.PNG
In addition to the escape sequence " required to insert a double quote within a double-quoted string, PHP understands the following escape sequences.

EscapeOutput
\nlinefeed character
\rCarriage return character.
\tTab character
\Backslash
$Dollar sign character

3. Heredoc notation.

The third way to input strings in php script is to use the heredoc syntax, an innovation seen in languages such as Perl and Bourne Shell scripting.

Below is a more clarification on the heredoc notaton.
Capture9.PNG
This is an example of text being input using the heredoc Notation in PHP. It is this basic to use and you can use any other tags as seen with the P tag.

Heredoc strings behave much like double quoted strings, although you do not need to escape as many of the characters - new line characters and tabs can be freely entered. In fact you do not need to worry about escaping $ characters.

The exact value of the terminating identifier (HTML in the example above) is not important, although some editors know to parse and colorize the text in particular ways when given specific values such as HTML, JAVASCRIPT, and so on.

The only constraint on the identifier is that it must contain only letters, numbers, and underscore characters, and the first character must be a letter or underscore.

4. Booleans.

Booleans are the simplest type in the PHP type system and express a binary value, TRUE or FALSE, YES or NO, 1 or 0. The value of the boolean variable can be either TRUE or FALSE
These two keywords are not case sensitive.
Capture10.PNG

If you try to print the value of the boolean variable or expression, you see a 1 and 0 for false.

Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Good evening . Very good and helpful topic about PHP.
Please upvote me!

Thank you :)

Should I continue developing on PHP 5.3 or migrate to PHP 7.0?

Coin Marketplace

STEEM 0.19
TRX 0.16
JST 0.030
BTC 68492.14
ETH 2699.27
USDT 1.00
SBD 2.72