您的位置:首页 > 其它

preg_match

2016-05-01 09:53 162 查看
preg_match ("/php/i", "PHP
is the web scripting language of choice.")

// 模式定界符后面的 "i" 表示不区分大小写字母的搜索

rv

/*
模式中的 \b 表示单词的边界,因此只有独立的 "web" 单词会被匹配,

* 而不会匹配例如 "webbing" 或 "cobweb" 中的一部分 */

if (preg_match ("/\bweb\b/i", "PHP
is the web scripting language of choice.")) {

print "A match was found.";

} else {

print "A match was not found.";\b

}

\b
xx \b 就是单词

<?php

// 从 URL 中取得主机名

preg_match("/^(http:\/\/)?([^\/]+)/i",

"http://www.php.net/index.html", $matches);

$host = $matches[2];

// 从主机名中取得后面两段

preg_match("/[^\.\/]+\.[^\.\/]+$/", $host, $matches);

echo "domain name is: {$matches[0]}\n";

?>

$str ='preg_match正则匹配中文123';

// 正则表达式匹配中文(UTF8编码)

if(preg_match('/[\x{4e00}-\x{9fa5}]+/u',$str)){

echo '匹配';

}else{

echo '没有匹配';

}

// 正则表达式匹配中文(GB2312,GBK编码)

preg_match("/^[".chr(0xa1)."-".chr(0xff)."A-Za-z0-9_]+$/",$str);

$loginPromt = '/username:.*|login:.*/i',

$passwordPromt = '/pass(word)?:.*/i',

$shellPromt = '/#$/i';
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: