SlideShare a Scribd company logo
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Hidaya Institute of
Science &
Technology
www.histpk.org
A Division of Hidaya Trust, Pakistan
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
String Functions and Operations
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
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.
•http://www.asciitable.com/
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
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);
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
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 />”;
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP strlen() Function
The strlen() function is used to return the length of a string.
Syntax
strlen(string)
Example
<?php
echo strlen("Hello world!");
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
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);
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP trim() Function
The trim() function removes whitespaces from both sides of a string.
Syntax
trim(string)
Example
<?php
echo trim(“ Hello World ”);
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 1
Enter String
Text
Click
Output
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 2 Enter String
Text
Click
Output
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 3
Enter String Text
Click
Output
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 4
Enter some
text here
Find
character
Replace
character
Click
Output
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 5
Enter Text
Click
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 5
Output
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 6
Characte
r
Output
Click
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 6
Characte
r
Output
Click
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 7
Enter Text
Click
Output
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP rand() Function
The rand() function generates a random integer.
If this function is called without parameters, it returns a random integer
between 0 and RAND_MAX.
If you want a random number between 10 and 100 (inclusive), use rand
(10,100).
Note: On some platforms (such as Windows) RAND_MAX is only 32768. So,
if you require a range larger than 32768, you can specify min and max, or
use the mt_rand() function instead.
The other random function, mt_rand() function generates a better random
value than this function .
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP rand() Function continue……
• Syntax
rand(min,max)
Example 1
<?php
echo(rand() . "<br />");
echo(getrandmax(). "<br />");
echo(rand(10,100));
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP rand() Function continue……
• Example 2
<?php
echo "<hr> mt_rand = ".mt_rand()."<hr>";
echo "<hr>rand = ".rand()."<hr>";
echo "<hr> mt_rand with range = ".mt_rand(1,100)."<hr>";
echo "<hr> rand with range = ".rand(1,100)."<hr>";
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP round() function
• The round() function rounds a number to the
nearest integer.
• Syntax:
• round(x,prec)
Parameter Description
x Required. The number to be round
prec Optional. The number of digits after the decimal point
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP round() function continued….
• Example 1
• <?php
• echo round(1.68) ;
• ?>
• Example 2
• <?php
• echo round(1.68,1) ;
• ?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP ceil() function
• The ceil() function returns the value of a number rounded
UPWARDS to the nearest integer.
Syntax
Ceil(x)
Example:
<?php
echo ceil(0.60);
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
• PHP floor() Function
• The floor() function returns the value of a number rounded
DOWNWARDS to the nearest integer.
Syntax
floor(x)
Example:
<?php
echo floor(0.60);
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP explode() Function
The explode() function breaks a string into an array.
Syntax
explode(separator,string)
Example
<?php
$string = "Hello world. It's a beautiful day.";
print_r (explode(" ",$string));
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
PHP implode() Function
The implode() function returns a string from the elements of an array.
Syntax
implode(separator,array)
Example
<?php
$array = array('Hello','World!','Beautiful','Day!');
echo implode(" ",$array);
?>
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 8
Disabled Textbox Click Generate
Password
Output
© Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org
Assignment # 9
Enter
Word
Click
Output

More Related Content

PPT
String functions and operations
PPT
String functions and operations
PPTX
Css presentation lecture 3
PPT
PHP array 2
PPTX
Dreamweaver cs6
PPTX
Dom in javascript
PPT
Web forms and html lecture Number 4
PPT
Java script lecture 1
String functions and operations
String functions and operations
Css presentation lecture 3
PHP array 2
Dreamweaver cs6
Dom in javascript
Web forms and html lecture Number 4
Java script lecture 1

Viewers also liked (15)

PPT
Javascript 2
PPTX
Css presentation lecture 1
PPT
Javascript lecture 3
PPTX
Sessions in php
PPTX
Css presentation lecture 4
PPT
Functions in php
PPTX
PHP array 1
PPT
Form validation with built in functions
PPT
Form validation server side
PPT
Javascript lecture 4
PPTX
loops and branches
PPT
Web forms and html lecture Number 3
PPTX
introduction to programmin
PPT
Form validation client side
PPT
Web forms and html lecture Number 2
Javascript 2
Css presentation lecture 1
Javascript lecture 3
Sessions in php
Css presentation lecture 4
Functions in php
PHP array 1
Form validation with built in functions
Form validation server side
Javascript lecture 4
loops and branches
Web forms and html lecture Number 3
introduction to programmin
Form validation client side
Web forms and html lecture Number 2
Ad

Similar to String functions and operations (20)

PPT
Reporting using FPDF
PPT
Introduction To PHP
PDF
PHP 5.4 New Features
PDF
20180420 hk-the powerofmysql8
PDF
More about PHP
PDF
Python and the MySQL Document Store
PDF
TWINS: OOP and FP - Warburton
PDF
First Steps in Python Programming
PPT
PHP complete reference with database concepts for beginners
PPTX
Introduction to php
PDF
PHP Arrays - indexed and associative array.
PDF
High-level Programming Languages: Apache Pig and Pig Latin
PDF
Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...
PDF
Php tutorial(w3schools)
PDF
Php tutorialw3schools
PPTX
Custom Component development Oracle's Intelligent Bot Platform
PPTX
Pa2 session 4
ODP
PHP BASIC PRESENTATION
PDF
LINQ Inside
Reporting using FPDF
Introduction To PHP
PHP 5.4 New Features
20180420 hk-the powerofmysql8
More about PHP
Python and the MySQL Document Store
TWINS: OOP and FP - Warburton
First Steps in Python Programming
PHP complete reference with database concepts for beginners
Introduction to php
PHP Arrays - indexed and associative array.
High-level Programming Languages: Apache Pig and Pig Latin
Reactive Java Programming: A new Asynchronous Database Access API by Kuassi M...
Php tutorial(w3schools)
Php tutorialw3schools
Custom Component development Oracle's Intelligent Bot Platform
Pa2 session 4
PHP BASIC PRESENTATION
LINQ Inside
Ad

More from Mudasir Syed (19)

PPT
Error reporting in php
PPT
Cookies in php lecture 2
PPT
Cookies in php lecture 1
PPTX
PPT
Oop in php lecture 2
PPT
Oop in php lecture 2
PPT
Filing system in PHP
PPT
Time manipulation lecture 2
PPT
Time manipulation lecture 1
PPT
Php Mysql
PPT
Adminstrating Through PHPMyAdmin
PPT
Sql select
PPT
PHP mysql Sql
PPT
PHP mysql Mysql joins
PPTX
PHP mysql Introduction database
PPT
PHP mysql Installing my sql 5.1
PPT
PHP mysql Er diagram
PPT
PHP mysql Database normalizatin
PPT
PHP mysql Aggregate functions
Error reporting in php
Cookies in php lecture 2
Cookies in php lecture 1
Oop in php lecture 2
Oop in php lecture 2
Filing system in PHP
Time manipulation lecture 2
Time manipulation lecture 1
Php Mysql
Adminstrating Through PHPMyAdmin
Sql select
PHP mysql Sql
PHP mysql Mysql joins
PHP mysql Introduction database
PHP mysql Installing my sql 5.1
PHP mysql Er diagram
PHP mysql Database normalizatin
PHP mysql Aggregate functions

Recently uploaded (20)

PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Lesson notes of climatology university.
PPTX
Institutional Correction lecture only . . .
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
RMMM.pdf make it easy to upload and study
PDF
Complications of Minimal Access Surgery at WLH
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
Presentation on HIE in infants and its manifestations
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
GDM (1) (1).pptx small presentation for students
Microbial diseases, their pathogenesis and prophylaxis
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Computing-Curriculum for Schools in Ghana
Lesson notes of climatology university.
Institutional Correction lecture only . . .
Supply Chain Operations Speaking Notes -ICLT Program
RMMM.pdf make it easy to upload and study
Complications of Minimal Access Surgery at WLH
102 student loan defaulters named and shamed – Is someone you know on the list?
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Anesthesia in Laparoscopic Surgery in India
Module 4: Burden of Disease Tutorial Slides S2 2025
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Presentation on HIE in infants and its manifestations
A systematic review of self-coping strategies used by university students to ...
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
GDM (1) (1).pptx small presentation for students

String functions and operations

  • 1. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Hidaya Institute of Science & Technology www.histpk.org A Division of Hidaya Trust, Pakistan
  • 2. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org String Functions and Operations
  • 3. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org 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. •http://www.asciitable.com/
  • 4. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org 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); ?>
  • 5. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org 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 />”; ?>
  • 6. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP strlen() Function The strlen() function is used to return the length of a string. Syntax strlen(string) Example <?php echo strlen("Hello world!"); ?>
  • 7. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org 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); ?>
  • 8. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP trim() Function The trim() function removes whitespaces from both sides of a string. Syntax trim(string) Example <?php echo trim(“ Hello World ”); ?>
  • 9. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 1 Enter String Text Click Output
  • 10. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 2 Enter String Text Click Output
  • 11. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 3 Enter String Text Click Output
  • 12. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 4 Enter some text here Find character Replace character Click Output
  • 13. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 5 Enter Text Click
  • 14. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 5 Output
  • 15. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 6 Characte r Output Click
  • 16. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 6 Characte r Output Click
  • 17. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 7 Enter Text Click Output
  • 18. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP rand() Function The rand() function generates a random integer. If this function is called without parameters, it returns a random integer between 0 and RAND_MAX. If you want a random number between 10 and 100 (inclusive), use rand (10,100). Note: On some platforms (such as Windows) RAND_MAX is only 32768. So, if you require a range larger than 32768, you can specify min and max, or use the mt_rand() function instead. The other random function, mt_rand() function generates a better random value than this function .
  • 19. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP rand() Function continue…… • Syntax rand(min,max) Example 1 <?php echo(rand() . "<br />"); echo(getrandmax(). "<br />"); echo(rand(10,100)); ?>
  • 20. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP rand() Function continue…… • Example 2 <?php echo "<hr> mt_rand = ".mt_rand()."<hr>"; echo "<hr>rand = ".rand()."<hr>"; echo "<hr> mt_rand with range = ".mt_rand(1,100)."<hr>"; echo "<hr> rand with range = ".rand(1,100)."<hr>"; ?>
  • 21. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP round() function • The round() function rounds a number to the nearest integer. • Syntax: • round(x,prec) Parameter Description x Required. The number to be round prec Optional. The number of digits after the decimal point
  • 22. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP round() function continued…. • Example 1 • <?php • echo round(1.68) ; • ?> • Example 2 • <?php • echo round(1.68,1) ; • ?>
  • 23. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP ceil() function • The ceil() function returns the value of a number rounded UPWARDS to the nearest integer. Syntax Ceil(x) Example: <?php echo ceil(0.60); ?>
  • 24. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org • PHP floor() Function • The floor() function returns the value of a number rounded DOWNWARDS to the nearest integer. Syntax floor(x) Example: <?php echo floor(0.60); ?>
  • 25. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP explode() Function The explode() function breaks a string into an array. Syntax explode(separator,string) Example <?php $string = "Hello world. It's a beautiful day."; print_r (explode(" ",$string)); ?>
  • 26. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org PHP implode() Function The implode() function returns a string from the elements of an array. Syntax implode(separator,array) Example <?php $array = array('Hello','World!','Beautiful','Day!'); echo implode(" ",$array); ?>
  • 27. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 8 Disabled Textbox Click Generate Password Output
  • 28. © Copyright 2012 Hidaya Trust (Pakistan) ● A Non-Profit Organization ● www.hidayatrust.org / www,histpk.org Assignment # 9 Enter Word Click Output