In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how php deletes strings between specified characters, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Php method to delete the string between the specified characters: 1, create a PHP sample file; 2, enter the code "public function getStr () {...}"; 3, delete the character between the specified two characters in the string through the getStr method.
This article operating environment: windows7 system, PHP7.1 version, Dell G3 computer.
PHP deletes the character between the two specified characters in a string
To do the problem in the project, you need to delete the character between the two specified characters in the string. Public function getStr () {/ / str is a string of regular strings, and now I want to delete one of them. The code is as follows: $str= "1pl 2018-04-1515 str= 1515 str= 22018-04-1513 20 str= 1131 2018-04-1515 1515 str= 11" / / get the start position, select, 2, (prevent conflict with the year of time) $i1=strpos ($str,',2,'); / / start position $i2=strpos ($str,',',$i1+3); / / end position $str1=substr ($str,0,$i1). Substr ($str,$i2,strlen ($str)); echo $str. "
". $str1;// line-breaking output, contrast result / / output result / / 1meme2018-04-15mm 20purl 15purl 11meme 2meme2018-04-15Eng 20purl 15purl 11meme 3meme2018-04-15Ensemble 20purl 15purl 11meme 4meme2018-04-15Ensemble 20purl 1511 / 1prime2018-04-15century 20purl 1511 / OK, perfect. } simply encapsulate it (it feels troublesome after encapsulation) But write it down, public function getStr ($str,$str1,$n1,$str2 (N2) {/ * $str is the string to be processed * $str1 is the only selected string * $N1 is intercepted from the first string in $str * $str2 is the selected unique string * $N2 is the end of the string in $str2 * / $i1=strpos ($str,$str1) + $N1 $i2=strpos ($str,$str2,$i1) + $N2; $str1=substr ($str,0,$i1-1). Substr ($str,$i2,strlen ($str)); return $str1;} take a chestnut and use the encapsulation method to make the following five values as follows: $str= "1 str1=", 2, "2"; $N1 = "2"; / / intercept $str2= ","; $N2 = "1" from 2 of the specified values; / / intercept to the first of the specified values, that is, echo (getStr ($str,$str1,$n1,$str2,$n2)); / / well, the result is the same, it's not easy, ha, above is all the content of the article "how to delete strings between specified characters by php", thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.