Home > Backend Development > PHP Tutorial > PHP regular matching and array traversal

PHP regular matching and array traversal

墨辰丷
Release: 2023-03-31 11:24:01
Original
2325 people have browsed it

This article mainly introduces PHP regular matching and array traversal. Interested friends can refer to it. I hope it will be helpful to everyone.

The example in this article describes the PHP ID card number checking class, as follows:

<?php
 class CIDMaker // 声明一个身份证号码检查类
 {
 var $id;
 var $err;
 var $idx = array(1,1,1,1,1,1,1,1,3,1,1,2,2,2,3,2,2,2,2,2,2,2,3,3,3,3);
 var $idy = array(0,1,2,3,4,5,6,7,4,8,9,0,1,2,5,3,4,5,6,7,8,9,0,1,2,3);
 function check($id_no)
 {
  $id_no = ucfirst($id_no); // 将英文字母转大写
  if(ereg("^[A-Z][0-9]{9}$", $id_no))
  {
  for($i=0;$i<10;$i++)
  $ch[$i] = substr($id_no,$i,1);
  $i = 0;
  // 将英文字母转为数字 BEGIN
  for ($char = "A"; $char != $ch[0]; $char++)
   $i++;
  // 将英文字母转为数字 END
  // 导入检查公式 BEGIN
  $id = $this->idx[$i]+$this->idy[$i]*9+$ch[1]*8+$ch[2]*7+$ch[3]*6+$ch[4]*5+$ch[5]*4+$ch[6]*3+$ch[7]*2+$ch[8]*1+$ch[9]*1;
  $id = (($id % 10) == 0) ? TRUE : FALSE;
  return $id;
  // 导入检查公式 END
  }
  else
  return 0;
 }
 }
?>
Copy after login

In addition, regarding ID number verification, this site also provides ID card ownership query The tools are as follows:

http://tools.jb51.net/bianmin/sfz

Summary: The above is the entire content of this article, I hope it can It will be helpful to everyone’s study.

Related recommendations:

PHP View the background, process and solution of the current variable type

php implements the image function of adding watermarks and text based on Imagick

php uses define to define constants

The above is the detailed content of PHP regular matching and array traversal. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template