substr function string interception usage analysis _php techniques in PHP

Source: Internet
Author: User

This article illustrates the use of substr function string interception in PHP. Share to everyone for your reference, specific as follows:

The SUBSTR function in PHP is defined as follows:

SUBSTR (String,start,length)

The parameter description is as follows:

String required. A string that stipulates the part to return.

Start
Necessary. Specify where to start the string.
Positive number-starts at the specified position of the string
Negative number-starts at the specified position starting at the end of the string
0-Starts at the first character in the string

Length

Optional. Specify the length of the string to be returned. The default is until the end of the string.
Positive number-The length returned from the position where the start parameter is located
Negative number-The length returned from the end of the string

The sample code is as follows:

<?php
 Echo substr ("Welcome to Www.jb51.net!", 0);//output as is, do not intercept
 echo "<br>";
 echo substr ("Welcome to www.jb51.net!", 4,14); 14 characters are continuously intercepted from the 4th character
 echo "<br>";
 echo substr ("Welcome to www.jb51.net!", -4,4); From the penultimate 4th intercept 4 characters
 echo "<br>";
 echo substr ("Welcome to www.jb51.net!", 0,-4); Intercept from the first character, intercept to the penultimate 4th character
?>

The results of the operation are as follows:

Welcome to www.jb51.net!
ome to www.jb5
net!
Welcome to www.jb51.

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.