In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how php filters strings to get only numbers. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Get method: 1. Use the for statement to loop through the string, use the is_numeric () function to extract the numeric characters in the body of the loop and use the ". =" operator to assemble a new string. 2. Using the rule, use the "preg_replace (" / [^ 0-9] / ",", $str) statement.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
Method 1: using the is_numeric () function
Use the for loop to iterate over the string $str, and use the is_numeric () function to determine whether $str [$I] is a numeric character. The is_numeric () function can detect whether a variable is a number or a numeric string.
Use is_numeric ($str [$I]) in the body of the loop to determine whether the $str [$I] character is a numeric character; if so, take it out and use ". =" to concatenate a numeric substring.
Look at the output:
01234567890
Method 2: use the preg_replace () function
This is the end of this article on "how php filters strings to get only numbers". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.