php 中文与英语正则表达式
发布:smiling 来源: PHP粉丝网 添加日期:2014-09-09 17:17:19 浏览: 评论:
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>php 中文与英语正则表达式</title>
- </head>
-
- <body>
- <form id="phpfensi.com" name="phpfensi.com" method="post" action="">
-
- <input name="url" type="text" />
- <input name="" type="submit" value="提交 "/>
- </form>
-
- </body>
- </html>
- <?php
- function funcChinese($str,$num1='',$num2='')
- {
- if($num1!='' and $num2!=''){
- return (preg_match("/^([x81-xfe][x40-xfe])
-
- {".$num1.",".$num2."}$/",$str))?true:false;
- }else{
- return (!eregi("[^x80-xff]","$str"))?
-
- true:false;
- }
- }
-
- if( $_POST)
- {
- if( funcChinese( $_POST['url'] ) )
- {
- echo '是中文';
- }
- else
- {
- exit('不是有效中文');
- }
- }
- ?>
分享到: