在那里我使用文本文件作为数据库,我的文本文件的内容如下....
SRC ---> M ---> 11/22/1995 ---> myPassword ---> 11/29/2013
我想要做的是编写一个php
代码,搜索src
并返回我使用以下代码搜索文本文件的密码..
<?php
$file = 'Database.txt';
$searchfor = 'src';
// the following line prevents the browser from parsing this as HTML.
header('Content-Type: text/plain');
// get the file contents, assuming the file to be readable (and exist)
$contents = file_get_contents($file);
// escape special characters in the query
$pattern = preg_quote($searchfor, '/');
// finalise the regular expression, matching the whole line
$pattern = "/^.*$pattern.*\$/m";
// search, and store all matching occurences in $matches
if(preg_match_all($pattern, $contents, $matches)){
echo implode("\n", $matches[0]);
}
else{
echo "No matches found";
}
?>
我怎么能让它回应密码....任何帮助将不胜感激...提前感谢... :)我知道使用文本文件作为数据库是不安全但仍然...
答案 0 :(得分:0)
我刚才输入了这段代码:
$strArray = explode(' ---> ',implode($matches[0]));
$name = $strArray[3];
echo "\n" . $name;
后:
if(preg_match_all($pattern, $contents, $matches)){
获得了一些帮助