0% found this document useful (0 votes)
25 views

String Functions and Operations: by Raja Afzal Shah

This document discusses various string functions in PHP including chr(), ord(), strlen(), substr(), and trim(). chr() returns the character for a given ASCII value. ord() returns the ASCII value of the first character of a string. strlen() returns the length of a string. substr() returns part of a string starting from a given position with an optional length. trim() removes whitespace from both sides of a string. Examples are provided for each function.

Uploaded by

Bin Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

String Functions and Operations: by Raja Afzal Shah

This document discusses various string functions in PHP including chr(), ord(), strlen(), substr(), and trim(). chr() returns the character for a given ASCII value. ord() returns the ASCII value of the first character of a string. strlen() returns the length of a string. substr() returns part of a string starting from a given position with an optional length. trim() removes whitespace from both sides of a string. Examples are provided for each function.

Uploaded by

Bin Roy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

String Functions and Operations

By Raja Afzal Shah


What Is String?
A string is a data type used in programming, such as an
integer and floating point unit, but is used to represent
text rather than numbers. It is comprised of a set of
characters that can also contain spaces and numbers.
For example, the word "hamburger" and the phrase "I
ate 3 hamburgers" are both strings. Even "12345" could
be considered a string, if specified correctly. Typically,
programmers must enclose strings in quotation marks for
the data to recognized as a string and not a number or
variable name.

• String is a collection of characters.


• String is a collection of ASCII characters.
PHP chr() Function
The chr() function returns a character from the
specified ASCII value.
Syntax
chr(ascii)
Example
<?php
echo chr(65);
echo chr(122);
?>
PHP ord() Function
The ord() function returns the ASCII value
of the first character of a string.
Syntax
ord(string)
Example
<?php
echo ord(“h”).”<br />”;
echo ord(“hello”).”<br />”;
?>
PHP strlen() Function
The strlen() function is used to return the length of a
string.

Syntax
strlen(string)
Example
<?php
echo strlen("Hello world!");
?>
PHP substr() Function
The substr() function returns a part of a
string.

Syntax
substr(string,start,length)
Example
<?php
echo substr("Hello world!",6);
echo substr("Hello world!",6,5);
?>
PHP trim() Function

The trim() function removes whitespaces from both sides


of a string.
Syntax
trim(string)
Example

<?php
echo trim(“ Hello World ”);
?>
Assignment # 1
Enter String Text

Click

Output
Assignment # 2

Click

Output
Assignment # 3

Click

Enter String Text

Output

You might also like