01c01-1.php

来自「介绍PHP5的给类型函数应用」· PHP 代码 · 共 29 行

PHP
29
字号
<?php// A function to detect zipcodes in a string.function detect_zipcode($string) {	// Use regex to look for zipcodes, return true or false	return preg_match('/\b\d{5}(-\d{4})?\b/', $string);}// Try a few examples:echo '<pre>';// A true example:if (detect_zipcode('Frederick, MD  21701-3883')) {	echo "Test 1: true\n";}// Another true example:if (detect_zipcode('The zipcode 26623 is the area in which I grew up.')) {	echo "Test 2: true\n";}// A False example:if (detect_zipcode('The Phone Number is 301-555-1212')) {	echo "Test 3: true\n";}// Another false example:if (detect_zipcode('426969-313109')) {	echo "Test 4: true\n";}echo '</pre>';?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?