Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- $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;
- }
- echo $userDeti['user_name'];
Add Comment
Please, Sign In to add comment