【发布时间】:2014-05-23 18:05:24
【问题描述】:
我有一个应用程序,用户可以在其中上传简历(将是 .doc 文件)。我通过上传文件夹上传该文件,该文件的名称存储在我的数据库中。
现在我想添加搜索模块,管理员可以在提供的文本框中输入关键字,并根据关键字获取用户详细信息。关键字应搜索所有简历并检查该关键字出现在任何简历中的天气。如果是,则返回用户详细信息。
我找到了this,但无法理解。请为我提供执行此操作的简单逻辑。
提前致谢
【问题讨论】:
我有一个应用程序,用户可以在其中上传简历(将是 .doc 文件)。我通过上传文件夹上传该文件,该文件的名称存储在我的数据库中。
现在我想添加搜索模块,管理员可以在提供的文本框中输入关键字,并根据关键字获取用户详细信息。关键字应搜索所有简历并检查该关键字出现在任何简历中的天气。如果是,则返回用户详细信息。
我找到了this,但无法理解。请为我提供执行此操作的简单逻辑。
提前致谢
【问题讨论】:
试试这个:
<?php
$file = 'somefile.txt';
$searchfor = 'name';
// 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 "Found matches:\n";
echo implode("\n", $matches[0]);
}
else{
echo "No matches found";
}
【讨论】: