PHP preg_match Ó÷¨
±¾º¯ÊýÒÔ pattern µÄ¹æÔòÀ´½âÎö±È¶Ô×Ö·û´® subject¡£±È¶Ô½á¹û·µ»ØµÄÖµ·ÅÔÚÊý×é²ÎÊý matches Ö®ÖУ¬matches[0] ÄÚÈݾÍÊÇÔ×Ö·û´® subject¡¢matches[1] ΪµÚÒ»¸öºÏºõ¹æÔòµÄ×Ö·û´®¡¢matches[2] ¾ÍÊǵڶþ¸öºÏºõ¹æÔòµÄ×Ö·û´®£¬ÓàÀàÍÆ¡£ÈôÊ¡ÂÔ²ÎÊý matches£¬ÔòÖ»Êǵ¥´¿µØ±È¶Ô£¬ÕÒµ½Ôò·µ»ØֵΪ true¡£
±¾º¯ÊýÒÔ pattern µÄ¹æÔòÀ´½âÎö±È¶Ô×Ö·û´® subject¡£±È¶Ô½á¹û·µ»ØµÄÖµ·ÅÔÚÊý×é²ÎÊý matches Ö®ÖУ¬matches[0] ÄÚÈݾÍÊÇÔ×Ö·û´® subject¡¢matches[1] ΪµÚÒ»¸öºÏºõ¹æÔòµÄ×Ö·û´®¡¢matches[2] ¾ÍÊǵڶþ¸öºÏºõ¹æÔòµÄ×Ö·û´®£¬ÓàÀàÍÆ¡£ÈôÊ¡ÂÔ²ÎÊý matches£¬ÔòÖ»Êǵ¥´¿µØ±È¶Ô£¬ÕÒµ½Ôò·µ»ØֵΪ true¡£
PHP preg_matchÕýÔò±í´ïʽµÄʹÓãº
ÀûÓà preg_match()£¬ÎÒÃÇ¿ÉÒÔÍê³É×Ö·û´®µÄ¹æÔòÆ¥Åä¡£Èç¹ûÕÒµ½Ò»¸öÆ¥Å䣬preg_match() º¯Êý·µ»Ø 1£¬·ñÔò·µ»Ø 0¡£»¹ÓÐÒ»¸ö¿ÉÑ¡µÄµÚÈý²ÎÊý¿ÉÒÔÈÃÄã°ÑÆ¥ÅäµÄ²¿·Ö´æÔÚÒ»¸öÊý×éÖС£ÔÚÑéÖ¤Êý¾ÝʱÕâ¸ö¹¦ÄÜ¿ÉÒÔ±äµÃ·Ç³£ÓÐÓà SUN JAVA Certification
$string = "football";
if (preg_match('/foo/', $string)) {
// Æ¥ÅäÕýÈ·
}
ÉÏÃæµÄÀý×Ó½«³É¹¦Æ¥Å䣬ÒòΪµ¥´Ê football ÀïÃæ°üº¬ foo¡£ÏÖÔÚÎÒÃÇÀ´ÊÔÒ»¸ö¸ü¸´Ôӵģ¬ÀýÈçÑéÖ¤Ò»¸ö Email µØÖ·¡£
$string = "first.last@domain.uno.dos";
if (preg_match(
'/^[^0-9][a-zA-Z0-9_]+
([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+
([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',
$string)) {
// ÑéÖ¤EmailµØÖ·
}
Õâ¸öÀý×Ó½«ÑéÖ¤³ö´Ë Email µØַΪÕýÈ·¸ñʽ¡£
Ïà¹ØÎĵµ£º
$_SERVER['PHP_SELF']
#µ±Ç°ÕýÔÚÖ´Ðнű¾µÄÎļþÃû£¬Óë document rootÏà¹Ø¡£
$_SERVER['argv']
#´«µÝ¸ø¸Ã½Å±¾µÄ²ÎÊý¡£
$_SERVER['argc']
#°üº¬´«µÝ¸ø³ÌÐòµÄÃüÁîÐвÎÊýµÄ¸öÊý£¨Èç¹ûÔËÐÐÔÚÃüÁîÐÐģʽ£©¡£
$_SERVER['GATEWAY_INTERFACE']
#·þÎñÆ÷ʹÓÃµÄ CGI ¹æ·¶µÄ°æ±¾¡£ÀýÈ磬“CGI/1.1”¡£
$_SER ......
<?php
class useful{
/*
* ³£Óú¯ÊýÀà
* ×÷ Õߣº¶à²ËÄñ
* ÁªÏµÓÊÏ䣺kingerq AT msn DOT com
* ´´½¨Ê±¼ä£º2005-07-18
* À´Ô´£ºhttp://blog.csdn.net/kingerq
*/
/*
* ¹¦ÄÜ£º¸ñʽ»¯Êý×Ö£¬ÒÔ±ê×¼MONEY¸ñʽÊä³ö
......
´ò¿ªEditplus£¬Ñ¡Ôñ¹¤¾ß=¡·ÅäÖÃÓû§¹¤¾ß£¬¾ÍÓõ±Ç°µÄĬÈÏ×éºÃÁË¡£µ¥»÷“Ìí¼Ó¹¤¾ß”Ñ¡ÔñµÚÒ»¸ö×ÓÏÌÐò”£¬È¡¸öÃû×Ö¸øËü£¬“PhpDebug”°É¡£ÔÚÃüÁîÖÐä¯ÀÀµ½php.exeµÄλÖ㬲ÎÊýÑ¡ÔñΪ“Îļþ·¾¶”£¬ÕâʱÎҵĽçÃæÉÏÁ½¸öÊäÈë¿òÖзֱðΪ“D:\usr\php.exe”ºÍ&ldquo ......
»ù´¡Ìâ
¡¡¡¡1.±íµ¥ÖÐ getÓëpostÌá½»·½·¨µÄÇø±ð?
¡¡¡¡´ð£ºgetÓû§¶Ë½«Êý¾Ý¼Óµ½URLºó£¬¸ñʽΪ”?×Ö¶Î1=ÊäÈëÊý¾Ý1&×Ö¶Î2=ÊäÈëÊý¾Ý2&..."¡£
¡¡¡¡ÓÉÓÚgetÌá½»²ÎÊýºó»áÔÚµØÖ·À¸ÖÐÏÔʾ³öÀ´£¬ËùÒÔ»á²úÉúÑÏÖصݲȫÎÊÌâ¡£
¡¡¡¡get´«ÊäµÄÊý¾ÝÁ¿Ð¡£¬get´«ÊäµÄÊý¾ÝÁ¿Ð¡£¬ÕâÖ÷ÒªÊÇÒòΪÊÜurl³¤¶ÈÏÞÖÆ;¶øpost¿ÉÒÔ´«Ê ......
<?php
function checkMobile($str)
{
$pattern = "/^(13|15)\d{9}$/";
if (preg_match($pattern,$str))
{
Return true;
}
else
{
Return false;
}
}
$str = checkMobile("15800000001");
......