The phpsubstr () function filters 4 numbers at the end. Today, a customer needs to generate 400 phone numbers in batches at the starting position of 10000. at the beginning, I directly generate a number such as 10004, but merchants do not like this number, the question of filtering the ending number is that a customer needs to generate 400 phone numbers in batches. the starting position is 10000. when I start to generate the number directly, a number such as 10004 appears, but merchants do not like this number, the number indicating that the ending number is 4 is filtered. I can use substr ($ str,-1) = 4. let's look at the code below.
The code is as follows: |
|
Include ("cn. php"); // database connection class. if you do not want to find it, go here. $ Db = new Db (); $ SQL = "select * from table name where isnew = 1 "; $ Query = $ Db-> query ($ SQL ); $ Rs = $ Db-> fetch ($ query, 0 ); USD I = 10000; Foreach ($ rs as $ v => $ vv) { If (substr ($ I,-1) = 4) { $ I ++; } $ SQL = "update table name set txtiphone = '$ I' where id =". $ vv ['id']; If ($ Db-> query ($ SQL )) { $ I ++; } } Echo 'batch update completed '; |
Substr () functions
Syntax
substr(string,start,length)
Parameters |
Description |
String |
Required. Specifies that a part of the string is to be returned. |
Start |
Required. Specifies where the string starts.
- Positive number-start at the specified position of the string
- Negative number-starting from the specified position at the end of the string
- 0-start at the first character in the string
|
Length |
Optional. Specifies the length of the string to be returned. The default value is until the end of the string.
- Positive number-return from the position of the start parameter
- Negative number-return from the end of the string
|
This site Original tutorial reprint indicated Source: http://www.bKjia. c0m/phper/php.html
...