In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces php how to get the first few strings, which has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to understand it.
In PHP, you can use the substr function to get the first few bits of a string, such as "substr (" abcdef ", 0,-1);", and the return value is the first few bits in the specified string.
This article operating environment: windows7 system, PHP7.1 version, Dell G3 computer.
Php gets the instance of the first few bits of the string (substr returns the substring usage of the string)
In practical project applications, it is often encountered to use php to obtain the first few bits of a string for comparison, assignment, and so on. Today I would like to share with you how to use php substr to get the first and last bits of a string and refer to the location.
Substr
(PHP 4, PHP 5)
Substr-returns a substring of a string
Description
String substr (string $string, int $start [, int $length])
Returns the string string the substring specified by the start and length parameters.
Parameters.
String
Enter a string.
Start
If start is a non-negative number, the returned string will start at the start position of string and start at 0. For example, in the string "abcdef", the character at position 0 is "a", the string at position 2 is "c", and so on.
If start is negative, the returned string begins by counting the start character forward at the end of the string.
If the length of string is less than or equal to start, FALSE is returned.
Example # 1 uses negative start
Length
If a positive length is provided, the returned string will include up to length characters starting at start (depending on the length of the string).
If a negative length is provided, many characters at the end of the string will be left out (from the end of the string if the start is negative). If start is not in this text, an empty string is returned.
If a length with a value of 0pm false or NULL is provided, an empty string will be returned.
If no length is provided, the returned substring starts at the start position and ends the string.
Example # 2 uses negative length
Return value
Returns the extracted substring or FALSE on failure.
Update log version notes
5.2.2-5.2.6 If the start parameter indicates the position of a negative truncation or beyond, false is returned. Other versions get the string from start.
Example
Basic usage of Example # 3 substr ()
Example # 4 substr () casting behaviour
The above routine outputs:
1) 'pe'
2) '54'
3) 'gr'
4)'1'
5) false
6) false
7) '1200'
Error / exception
Returns FALSE when an error occurs.
Thank you for reading this article carefully. I hope the article "how to get the first few strings in php" shared by the editor will be helpful to you. At the same time, I also hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.