我想要以下内容:我有一个字符串,我想从数据库中搜索该字符串中的用户名,例如:
"Dear user, xy xy xy, Kind Regards, me"
而且,我想从数据库中查找字符串中的所有用户名,并将其替换为链接,例如(函数的输出):
"Dear <a href="link.php?user=user">user</a>, xy xy xy, Kind Regards, <a href="link.php?user=me">me</a>"
要检查所有用户名,我会使用红豆PHP:
$alluser = R::getAll('SELECT * FROM user')
我刚刚为它创建了一个代码:
function mention($string) {
$alluser = R::getAll('SELECT * FROM user');
foreach ($alluser as $user) {
//The Regular Expression filter
$reg_exUrl = "/".$user['username']."/";
if (preg_match_all($reg_exUrl, $string, $usernames)) {
foreach ($usernames as $username) {
$search = $username;
$replace = '<a href="user.php?tmpid='.$user['tmpid'].'">' . $user['username'] . '</a>';
$string = str_replace($search, $replace, $string);
if (strlen($allmention) > 0) {
$spacecomma = ", ";
} else $spacecomma = "";
$allmention .= $spacecomma . $user['tmpid'];
}
}
}
return $string;
}
引发以下错误:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function mention(), 0 passed in xyz.php on line 65 and exactly 1 expected in xyz.php:34 Stack trace: #0 xyz.php(65): mention() #1 {main} thrown in xyz.php on line 34
白板的微信
MYYA