PHP Learning-Get string substring

Source: Internet
Author: User

Substr

The function of getting substrings in PHP is substr that this function is very simple and the function prototype is as follows:

substr(string,start,length)
Parameters Description
String Necessary. A string that specifies the part to return.
Start Necessary. Specifies where to start the string. Positive number-start negative at the specified position of the string-starting at the specified position starting at the end of the string 0-starts at the first character in the string
Length Optional. Specifies the length of the string to be returned. The default is until the end of the string. Positive number-length negative number returned from the position of the start parameter-length returned from the end of the string

This is very simple. For a few examples:

<?phpecho substr("Hello world",6);?>//这个输出world
Explode

This is a string cut function, similar to the function of split.
The prototype of this function is:

explode(separator,string,limit)
Parameters Description
Separator Necessary. Specifies where to split the string.
String Necessary. The string to split.
Limit Optional. Specifies the number of array elements that are returned. Possible values: greater than 0-returns an array containing a maximum of limit elements less than 0-returns an array containing all elements except the last-limit element 0-Returns an array containing an element

The distance is as follows:

<?php$str = "Hello world. I love Shanghai!";print_r (explode(" ",$str));?>

This is: Break the string into arrays.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

PHP Learning-Get string substring

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.