我有一个类似 sql 的语句:
Select * FROM table WHERE content LIKE '%word%'
这将返回在列内容中找到“word”的所有行。但是是否可以向该语句添加一个参数,以便我只返回找到“单词”两次(或三次、四次或五次……)次的行。
最佳答案
窃取@thebjorn 的评论但使其更通用:
$theword = "word"; // apply appropriate escaping, especially with user input
// you will also need to manually escape % and _
$count = 4;
$like_condition = str_repeat("%".$theword,$count)."%";
$query = "select * from table where content like '".$like_condition."'";
关于php - 使用 like 语句仅返回出现 x 次的命中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21970971/