我想要以下内容:我有一个字符串,我想从数据库中搜索该字符串中的用户名,例如:"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
2 回答
白板的微信
TA贡献1883条经验 获得超3个赞
您的错误与您发布的代码无关。错误出在调用该函数的代码中。它应该被称为像mention
$result_string = mention($initial_string)
但判断是错误,它被称为像
$result_string = mention()
- 2 回答
- 0 关注
- 91 浏览
添加回答
举报
0/150
提交
取消