【发布时间】:2014-06-28 16:53:21
【问题描述】:
我想知道是否有一种快速的方法来获得这样的一行:
Name (Database comumn) would be a database like |ID|Name|Age|Gender|
不在表中:
Text (long string)
姓名:
John Smith
Jack Stone
Brian Woods
Text: "Someone was going to go to John Smith but instead went to Brian Woods. Why would he do that to John Smith?"
查询应该返回“John Smith”匹配 2 次,“Brian Woods”匹配 1 次
你是如何得到这么快的?
$text = "Someone was going to go to John Smith but instead went to Brian Woods. Why would he do that to John Smith?";
$query = $mysql("SELECT * FROM persons");
while($r = mysql_fetch_assoc($query))
{
if(preg_match("/".$r["Name"]."/", $text))
{
$matches[$r["name"]]+=1;
}
}
print_r($matches);
【问题讨论】:
-
是的,有可能。但是,您应该提供无效的代码。
-
添加了它,很抱歉它确实有效,但在包含 3000 条记录的数据库中,这太慢了。
标签: php mysql sql pattern-matching match