PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




PHP substr Function


Tutorials »Php »

Topic

What is substr Function?



Explanation

In PHP, this function returns a part of a string.

Syntax:
    substr(string,start,length)

In the above syntax given "string" is input to return , "start" specifies where to start in the input, "length" specifies the length of the part of a string.Usually the "start","length" can have positive and negative number,which refers to starting and ending of a string.

Example:
    <?php
    echo substr("abcdef", -1);
    echo substr("abcdef", -2);  
    echo substr("abcdef", 0, -1);  
    echo substr("abcdef", 2, -1);  
    ?>
Result:
    f
    ef
    abcde
    cde

In the above example first the start value is "-1" so last character "f" is taken, in another example start value is "0" so the string from the start is taken and since length is "-1" it leaves a character from the end to display output.





A Note

Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial. Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.

Other Links

web hosting