hi我正在使用一个文本文件作为数据库,我的文本文件的内容如下。。。。
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";
}
?>
我怎样才能使它与密码相呼应。。。。任何帮助都将不胜感激。。。提前感谢…:)我知道使用文本文件作为数据库是不安全的,但仍然。。。
我刚刚输入了以下代码:
$strArray = explode(' ---> ',implode($matches[0]));
$name = $strArray[3];
echo "'n" . $name;
之后:
if(preg_match_all($pattern, $contents, $matches)){
我从PHP那里得到了一些帮助-从字符串中获取特定单词