用file方法获得的数组元素是包含行结束符(换行符)的,所以直接比对的话肯定是不匹配的.可以用rtrim()函数把行结束符去掉再来比对,但建议最好换成逐行读取文件的方式而不是直接用file函数读取到数组中
php
$localhost?=?'localhost';//本地的基本是用localhost
$dbname?=?'dbname';//数据库名
$user?=?'user';//用户名
$pw?=?'pw';//密码
$pdo?=?new?PDO("mysql:host=".$localhost.";dbname=".$dbname."",$user,$pw);?
$username?=?$_POST['username'];
$userpassword?=?$_POST['userpassword'];
$sql?=?'SELECT?userpassword?FROM?◆userinf◆?WHERE?◆username◆="'?.?$username?.?'"';
$row?=?$pdo-query($sql)-fetch();//查询数据库
if($userpassword?==?$row['userpassword'])
{
@header("Location:?http://网址");//配对成功,跳转
}
else
exit('不好意思,你的密码不对');
/*
而且POST提交过来的数据也要过滤一下
*/
html?xmlns=""
head
title用户登录验证/title
/head
body
form?method="POST"
用户名:input?name="username"?type="text"?/?|?密码:input?name="userpassword"?type="password"?/?|?input?type="submit"?value="提交"
/form
/body
/html
先用正则表达式匹配tr标签内的数据,再用正则表达式匹配td标签内的数据
完整的php程序如下
preg_match_all?('/tr?class="text-c"(.◆?)\/tr/im',?$str,?$result);
for?($i=0;?$icount($result[1]);?$i◆◆)?{
$s=$result[1][$i];
preg_match_all?('/td.*?(.◆?)\/td/im',?$s,?$matches);
for?($j=0;?$jcount($matches[1]);?$j◆◆)?{
echo?$matches[1][$j]."br";
以上就是土嘎嘎小编为大家整理的php匹配数据相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!