如何判断字符串是否合法? 本帖最后由 dahua20000 于 2011-06-23 20:55:12 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1. 正则表达式的定义要放在"//"之间。2. 你的办法是要找非字母或数字的字符,应该是"/[^0-9A-Za-z]/".$the_str= "123123avfghkjl_hello";$res=preg_match('/[^0-9A-Za-z]/',$the_str);if(0==$res){ echo "合法字符串";}else{ echo "无效字符串";} if(ereg('[^0-9A-Za-z]',$test_string)) // will be true if characters arnt 0-9, A-Z or a-z. if(preg_match('/[^0-9A-Za-z]/',$test_string)) // this is the preg_match version. the /'s are now required. 关于php采集淘宝卖家成交记录的问题 请教一下smarty 如何遍历对象 关于php找不到网页 一个PHP和AJAX相关的问题!急啊 google2009年在华南地区的两道笔试题目 关于PHP中单件模式的问题 请问,在IIS做好的PHP程序放在LINUX的APACHE服务器中能正常运行吗? 如何写 php上传下载的小程序急用! 函数 mail( $to, $subject, $Message) 的第二个参数可不可以是 $name+$subject ?也就是说把这两个变量和成为一个字符串? 跨域 个人PHP技术展示,请指教。。。 关于php和html关系问题
2. 你的办法是要找非字母或数字的字符,应该是"/[^0-9A-Za-z]/".$the_str= "123123avfghkjl_hello";
$res=preg_match('/[^0-9A-Za-z]/',$the_str);
if(0==$res)
{
echo "合法字符串";
}
else
{
echo "无效字符串";
}
if(ereg('[^0-9A-Za-z]',$test_string)) // will be true if characters arnt 0-9, A-Z or a-z. if(preg_match('/[^0-9A-Za-z]/',$test_string)) // this is the preg_match version. the /'s are now required.