Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 39

ITELEC1: OBJECT-ORIENTED PROGRAMMING

USING PHP LANGUAGE

Presented to :
BSIT 1st Year – BLOCK 1, 2, 3, 4, 5, 6, 26 & 27
HERNAN E. TRILLANO, CPCA
Certified Professional Cloud Architect
TABLE OF CONTENTS

PHP COMMENTS DATA TYPES


01 01 03
03
Learn different types of PHP Comments Know different data types in PHP.

ECHO AND PRINT STATEMENTS PHP STRING


02 04
Know the basic input of using echo and print. Know how to apply strings in php.
02 04

06

3
TOPIC #1
PHP COMMENTS
WHAT IS A PHP COMMENT ?

• A comment in PHP code is a line that is not executed as a part of the


program. Its only purpose is to be read by someone who is looking
at the code.
• Comments can remind you of what you were thinking when you
wrote the code

6
SINGLE-LINE PHP COMMENTS

<?php
// This is a single-line comment

# This is also a single-line comment


?>
7
MULTIPLE-LINE PHP COMMENT
<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?> 8
COMMENT APPLICATION
<?php
// You can also use comments to
leave out parts of a code line
$x = 5 /* + 5 */ + 5;
echo $x;
?> 9
TOPIC
#2
PHP ECHO AND PRINT
STATEMENTS
WHAT IS ECHO AND PRINT IN PHP?

Echo and print are more or


less the same. 1
They are both used to output
2 data to the screen.

Echo has no return value


3

11
Print has a return value of 1.
4

Echo is marginally faster than


print. 5

Echo can be declared :


6 “echo” or “echo()”

Print can be declared :


“print” or “print()” 7

12
Echo can take multiple
8 parameters.

Print can take one argument.


9

13
The PHP echo statement.
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ",
"with multiple parameters.";
?> 14
The PHP print statement.

<?php
print "<h2>PHP is Fun!</h2>";
print "Hello world!<br>";
print "I'm about to learn PHP!";
?>
15
TOPIC #3
PHP DATA TYPES
PHP SUPPORTS THE FOLLOWING DATA TYPES:

STRING 01
INTEGER 02
FLOAT 03
BOOLEAN 04

17
PHP SUPPORTS THE FOLLOWING DATA TYPES:

ARRAY 01
OBJECT 02
NULL 03
RESOURCE 04

18
PHP STRING

• A string is a sequence of characters, like "Hello world!".


• A string can be any text inside quotes. You can use single or
double quotes

Hello world!
Hello world!

19
PHP INTEGER
• An integer data type is a non-decimal number between -2,147,483,648 and
2,147,483,647.
• In the following example $x is an integer. The PHP var_dump() function returns the
data type and value:

int(5985)

20
PHP FLOAT
• A float (floating point number) is a number with a decimal point or
a number in exponential form.
• In the following example $x is a float. The PHP var_dump() function
returns the data type and value:

float(10.365)

21
PHP BOOLEAN

• A Boolean represents two possible states: TRUE or FALSE.


• Booleans are often used in conditional testing.

$x = true;
$y = false;

22
PHP ARRAY

• An array stores multiple values in one single variable.


• In the following example $cars is an array. The PHP var_dump()
function returns the data type and value:

23
PHP NULL

• Null is a special data type which can have only one value: NULL.
• A variable of data type NULL is a variable that has no value assigned to it.
Tip: If a variable is created without a value, it is automatically assigned a
value of NULL. Variables can also be emptied by setting the value to NULL:

NULL

24
PHP RESOURCE

• The special resource type is not an actual data


type. It is the storing of a reference to functions
and resources external to PHP.
• A common example of using the resource data
type is a database call.

25
PHP RESOURCE

26
TOPIC #4
PHP
STRINGS
PHP STRING

• A string is a sequence of characters, like "Hello


world!“ or ‘Hello World’. You can use double or
single quotes, but you should be aware of the
differences between the two.

28
strlen( )
The PHP strlen( ) function returns the length of a string.

Example:

29
str_word_count( )

The PHP str_word_count() function counts the number of words in a string.

Example:

30
strrev( )

The PHP strrev() function reverses a string.

Example:

31
strpos( )
• The PHP strpos() function searches for a specific text within a string. If
a match is found, the function returns the character position of the first
match.

Example:

32
str_replace( )
• The PHP str_replace() function replaces some characters with some other
characters in a string.

Example:

33
strtoupper( )

• The strtoupper() function returns the string in upper case:

Example:

34
strtolower( )

• The strtolower() function returns the string in lower case:

Example:

35
trim( )

• The trim() removes any whitespace from the beginning or the end:

Example:

36
explode( )
• The PHP explode() function splits a string into an array. The first parameter
of the explode() function represents the "separator".

Example:

37
Character Cases

38
THANK
YOU!!! 39

You might also like