In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "php replacement expression how to write", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "php replacement expression how to write" it!
Php substitution expressions are written in the following ways: 1, "str_ireplace ($search, $replace, $str);" way; 2, "substr_replace ($str, $replace, 0Magne5);" way.
This article operating environment: Windows7 system, PHP7.1 version, Dell G3 computer.
How to write the php replacement expression?
PHP string substitution
In PHP, you can replace specific characters or substrings in a string, which is a very common feature.
Str_ireplace () and str_replace () functions
Str_ireplace () and str_replace replace the specific string specified in the original string with a new string, str_replace is case-sensitive, str_ireplace () is not case-sensitive, and the syntax is similar.
The syntax for str_ireplace () is as follows:
Mixed str_ireplace (mixed $search, mixed $replace, mixed $subject [, int & $count])
This function returns a string or array. This string or array is the result of replacing all search in subject with replace (ignoring case). The parameter count represents the number of times the replacement was performed.
Examples of use are as follows:
The output from executing the above code is:
Hi,world,hi,world
Substr_replace () function
The syntax of the substr_replace () function is as follows:
Mixed substr_replace (mixed $string, mixed $replacement, mixed $start [, mixed $length])
Substr_replace () replaces the substrings qualified by the start and optional length parameters with replacement in the copy of the string string.
If start is positive, the replacement starts at the start position of the string. If the start is negative, the replacement starts at the penultimate start of the string.
If the length parameter is set and is a positive number, it indicates the length of the substring to be replaced in the string. If set to a negative number, it indicates the number of characters at the end of the substring to be replaced from the end of the string. If this parameter is not provided, it defaults to strlen (string) (the length of the string). Of course, if length is 0, then the function of this function is to insert replacement into the start location of the string.
Examples of the use of this function are as follows:
The execution result of the above code is:
Hi,world,hello,world thank you for reading, the above is "how to write php replacement expression" content, after the study of this article, I believe you have a deeper understanding of how to write php replacement expression, the specific use of the need for practice to verify. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.