PHP substr function string truncation usage analysis, phpsubstr_PHP tutorial

Source: Internet
Author: User
PHP substr function string truncation usage analysis, phpsubstr. Analysis on the use of substr function string truncation in PHP. phpsubstr this article describes the use of substr function string truncation in PHP. For your reference, we will share the following details: analysis of the substr function string truncation usage in subs PHP in PHP, phpsubstr

This example describes how to intercept the substr function string in PHP. We will share this with you for your reference. The details are as follows:

The substr function in PHP is defined as follows:

Substr (string, start, length)

Parameters are described as follows:

String is required. Specifies that a part of the string is to be returned.

Start
Required. Specifies where the string starts.
Positive number-start at the specified position of the string
Negative number-start at the specified position starting from the end of the string
0-start at the first character in the string

Length

Optional. Specifies the length of the string to be returned. The default value is until the end of the string.
Positive number-length returned from the position of the start parameter
Negative number-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, no echo is intercepted"
"; Echo substr (" Welcome to www.jb51.net! ", 4, 14); // A string of 14 consecutive echo characters starting from 4th characters"
"; Echo substr (" Welcome to www.jb51.net! ",-4th); // 4 characters of echo are intercepted starting from the last"
"; Echo substr (" Welcome to www.jb51.net! ", 0,-4); // starts from the first character, and is truncated to the last 4th characters?>

The running result is as follows:

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

I hope this article will help you with PHP programming.

Articles you may be interested in:
  • How to use the substr_count () function in PHP to obtain the occurrence times of a substring
  • PHP uses the strstr () function to obtain all characters after a specified string
  • The strncmp () function in PHP compares the first two characters of two strings to determine whether they are equal.
  • In PHP, the strnatcmp () function "natural sorting algorithm" is used to analyze the usage of string comparison (compared with the strcmp function)
  • Comparison and usage of strcmp () and strcasecmp () functions in PHP
  • PHP uses the trim function to remove leading and trailing spaces of strings and special character instances
  • PHP-encapsulated string encryption and decryption functions
  • The most accurate php string length truncation function
  • PHP uses substr () to intercept strings. what should I do if Chinese characters are garbled?
  • Summary of common PHP string operation function instances

Examples in this article describes the use of the substr function string truncation in PHP. Share it with you for your reference. The details are as follows: subs in PHP...

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.