













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to php, a widely-used, open source scripting language for creating dynamic and interactive web pages. It covers php syntax, variables, data types, operators, functions, and constants. The document also explains how to install php and execute php scripts. It is a useful resource for university students, high school students, and lifelong learners who are interested in web development and php programming.
Typology: Slides
1 / 21
This page cannot be seen from the preview
Don't miss anything!














PHP
for making dynamic and interactive Web pages.
PHP code.
returned to the browser as plain HTML.
XAMPP
PHP Basic Syntax
The default file extension for PHP files is “.php”
Welcome to PHP
PHP Case Sensitivity
";
echo "Hello World!";
EcHo "Hello World!";
Variables
In PHP, a variable starts with the $ sign, followed by
the name of the variable:
have to specify datatype with variable. PHP
automatically converts the variable to the correct data
type, depending on its value.
Rules for PHP variables:
A variable starts with the $ sign, followed by the name of
the variable
A variable name must start with a letter or the underscore
character
A variable name cannot start with a number
A variable name can only contain alpha-numeric
characters and underscores (A-z, 0-9, and _ )
Variable names are case-sensitive ($age and $AGE are
two different variables)
For example:
Output Statement
";
$name = "Ali ";
echo $name;
print "PHP";
echo "I ", "am ", "in ", "5th ", "semester. ";
//print "I ", "am ", "in ", "5th ", "semester"; This is not allowed
?>
Data Types
Float
Boolean
String Functions
There are lots of string functions available in PHP. Some of
these are presented here;
Length of a String
returns the number of bytes in a string.
echo strlen("Web"); // Outputs 3
Count The Number of Words in a String
string:
echo str_word_count("Web Engineering"); // outputs 2
Reverse a String
echo strrev("Web"); // output is beW
String Functions (Cont…)
Constants
A constant is an identifier (name) for a simple value.
The value cannot be changed during the script.
underscore (no $ sign before the constant name).
global across the entire script.
define( name , value , case-insensitive )
name : Specifies the name of the constant
value : Specifies the value of the constant
case-insensitive : Specifies whether the constant
name should be case-insensitive. Default is false.
Constant (Cont…)