PHP substr() string function

The substr() function in PHP

The substr() function used to returns some portion of given string by assign start and length values.

substr() function syntax

substr(“string”, start, length);

PHP strsub() function example

In above strsub() function example the string = “Meera Academy” and start from 1st index to 6 character .The index value always start from 0, so here we assign start to 1 then the string returns from second character to six character.

The white space calulated in a string.

The out put is :

The substring of stirng = eera A

substr() function example with php form

Here, we create php form firstexample.php with three textboxes and a submit button control. In first textbox get string value from user and second textbox is the start position of substring and the last length textbox is the character length of substring.

In above php substr() function we entered “Meera Academy” text in¬†name¬†textbox and the start postion =1 and the length=6, so out put result = “eera A”. The first character start position is 0.

PHP substr() string function

PHP substr() string function

 

Leave a Reply

Your email address will not be published. Required fields are marked *

8 + 9 =


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">