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.
© 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

More Related Content

PPT
String functions and operations
PPT
String functions and operations
PPT
Javascript lecture 4
PPT
Java script lecture 1
PPTX
PHP string-part 1
PPTX
php string part 3
PPTX
Tokens in php (php: Hypertext Preprocessor).pptx
PPTX
strings in php how to use different data types in string
String functions and operations
String functions and operations
Javascript lecture 4
Java script lecture 1
PHP string-part 1
php string part 3
Tokens in php (php: Hypertext Preprocessor).pptx
strings in php how to use different data types in string

Similar to String functions and operations (20)

PPTX
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
PPTX
UNIT II (7).pptx
PPTX
UNIT II (7).pptx
PDF
php_string.pdf
ODP
PHP Web Programming
PPTX
Strings cprogramminglanguagedsasheet.pptx
PPTX
Working With Variables-[LAA] PHP Lj.pptx
PPTX
ession Outcomes: By the end of this session, learners will be able to: Unde...
PPTX
String variable in php
PDF
String functions
PPT
Strings
PPT
Strings
PPT
Strings
PDF
strings.pdf
PPTX
varthini python .pptx
PDF
Character Array and String
PPTX
Php string function
PPT
Php, mysqlpart2
PPSX
Strings
String handling and arrays by Dr.C.R.Dhivyaa Kongu Engineering College
UNIT II (7).pptx
UNIT II (7).pptx
php_string.pdf
PHP Web Programming
Strings cprogramminglanguagedsasheet.pptx
Working With Variables-[LAA] PHP Lj.pptx
ession Outcomes: By the end of this session, learners will be able to: Unde...
String variable in php
String functions
Strings
Strings
Strings
strings.pdf
varthini python .pptx
Character Array and String
Php string function
Php, mysqlpart2
Strings
Ad

More from Mudasir Syed (20)

PPT
Error reporting in php
PPT
Cookies in php lecture 2
PPT
Cookies in php lecture 1
PPTX
PPT
Reporting using FPDF
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
Reporting using FPDF
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
Ad

Recently uploaded (20)

PPTX
master seminar digital applications in india
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Institutional Correction lecture only . . .
PDF
Pre independence Education in Inndia.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
Lesson notes of climatology university.
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Classroom Observation Tools for Teachers
master seminar digital applications in india
GDM (1) (1).pptx small presentation for students
Institutional Correction lecture only . . .
Pre independence Education in Inndia.pdf
Insiders guide to clinical Medicine.pdf
RMMM.pdf make it easy to upload and study
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Basic Mud Logging Guide for educational purpose
Abdominal Access Techniques with Prof. Dr. R K Mishra
Final Presentation General Medicine 03-08-2024.pptx
VCE English Exam - Section C Student Revision Booklet
Lesson notes of climatology university.
TR - Agricultural Crops Production NC III.pdf
2.FourierTransform-ShortQuestionswithAnswers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Microbial diseases, their pathogenesis and prophylaxis
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
O7-L3 Supply Chain Operations - ICLT Program
Classroom Observation Tools for Teachers

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.
  • 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