Guest User

Untitled

a guest
Dec 14th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. function getMentions($content) {
  2. global $db;
  3. $mention_regex = "/@+([a-zA-Z0-9-_]+)/"; //mention regrex to get all @texts
  4. $regexIt = preg_match_all($mention_regex, $content, $matches);
  5. if ($regexIt) {
  6. foreach ($matches[1] as $key => $match) {
  7. if ($key === 0) continue;
  8. $mentioned[] = mysqli_real_escape_string($db, $match[0]);
  9. $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));
  10. $userDeti = mysqli_fetch_array($match_user, MYSQLI_ASSOC);
  11. $match_search = '@' . $match . '';
  12. $match_replace = '<a target="_blank" href="' . $userDeti['user_name'] . '">@' . $userDeti['user_name'] . '</a>';
  13. if (isset($userDeti['user_name'])) {
  14. $content = str_replace($match_search, $match_replace, $content);
  15. }
  16. }
  17. }
  18. return $content;
  19. }
  20.  
  21. echo $userDeti['user_name'];
Add Comment
Please, Sign In to add comment