In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "the solution to the error of numeric type substring in string judged by php using strpos". In daily operation, it is believed that many people have doubts about the solution to the error of numeric type substring in string judged by php using strpos. The editor has consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer the question of "php uses strpos to judge the solution to the error of numeric type substring in string"! Next, please follow the editor to study!
1. Question:
In recent development, I used the following test code to determine whether a random number is in a given string in the program code:
The winning number of $string=' is: 3 thanks to numtmpp / string,$numtmp (1); if (strpos ($string,$numtmp)! = = false) {echo "Congratulations! winning number:". $numtmp;} else {echo "Thank you! welcome to come again, the winning number is not". $numtmp;}
There is a problem with the runtime! When the random number reaches 3, it should judge the success and output "Congratulations! winning number: 3", but the program is handled according to false.
2. Solution:
Looking at the usage of the strpos function, it is found that the function has strict requirements for parameter types! Therefore, you need to cast the type!
You can modify the code as follows:
The winning number of $string=': 3 numbers: (string) numtmp = (1p10); / / cast the type here, changing the numeric type to the string type! If (strpos ($string,$numtmp)! = = false) {echo "Congratulations on winning the lottery! winning number:". $numtmp;} else {echo "Thank you! welcome again, the winning number is not". $numtmp;}
Run the code and solve the problem.
At this point, the study on "php uses strpos to determine the solution to the error of numeric type substrings in a string" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.