- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
substr() function in PHP
The substr() function is used to return a part of a string.
Syntax
substr(str, begin, len)
Parameters
str − The string
begin − Specifies where to begin in the string
A positive number − Start at a specified position in the string
A negative number − Start at a specified position from the end of the string
0 − Start at the first character in string
len − Specifies the length of the returned string. Default is to the end of the string.
A positive number − The length to be returned from the start parameter
Negative number − The length to be returned from the end of the string
Return
The substr() function returns the extracted part of the string.
Example
The following is an example −
<?php echo substr("This is it!",5); ?>
Output
is it!
Example
The following is an example −
<?php echo substr("programming language",2,6)."<br>" ?>
Output
ogramm <br>
Example
Let us see another example that includes negative parameters −
<?php echo substr("website development",-5,-2)."<br>" ?>
Output
pme <br>
Advertisements