Phpsubstr () function to implement filtering the ending number as 4 _ PHP Tutorial

Source: Internet
Author: User
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

...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.