以下功能未获得正确的结果:
function getMentions($content) {
global $db;
$mention_regex = "/@+([a-zA-Z0-9-_]+)/"; //mention regrex to get all @texts
$regexIt = preg_match_all($mention_regex, $content, $matches);
if ($regexIt) {
foreach ($matches[1] as $key => $match) {
if ($key === 0) continue;
$mentioned[] = mysqli_real_escape_string($db, $match[0]);
$match_user = mysqli_query($db, "SELECT user_id, user_name FROM dot_users WHERE user_name IN ('" . implode("','", $matches[1]) . "')") or die(mysqli_error($db));
$userDeti = mysqli_fetch_array($match_user, MYSQLI_ASSOC);
echo $userDeti['user_id'];
echo $userDeti['user_name'];
$match_search = '@' . $match . '';
$match_replace = '<a target="_blank" href="' . $userDeti['user_name'] . '">@' . $userDeti['user_name'] . '</a>';
if (isset($userDeti['user_name'])) {
$content = str_replace($match_search, $match_replace, $content);
}
}
}
return $content;
}
例如,我想在屏幕上打印user_name和user_id,但不打印。
echo $userDeti['user_id']; // echo is empty
echo $userDeti['user_name']; //echo is empty output
您能告诉我我做错了还是不完整的事情?
答案 0 :(得分:1)
我未经测试的建议...
module.exports = {
mode : 'production',
// Don't attempt to continue if there are any errors.
bail : true,
devtool : shouldUseSourceMap ? 'source-map' : false,
// In production, we only want to load the app code.
entry : [paths.appIndexJs],
output : {
// The build folder.
path : paths.appBuild,
filename : 'static/js/[name].[chunkhash:8].js',
chunkFilename : 'static/js/[name].[chunkhash:8].chunk.js',
publicPath : publicPath,
devtoolModuleFilenameTemplate : info =>
path
.relative(paths.appSrc, info.absoluteResourcePath)
.replace(/\\/g, '/')
},
...}
可能有错别字,但总的思路就在那里。捕获提及内容并尝试避免发送电子邮件,查找ID,替换所有提及内容。