Code: Select all
function mentiune($string)
{
// Modificati cu variabila voastra MySQLi.
global$sqli;
$regex_mentiune = "/@+([a-zA-Z0-9_-]+)/i";
preg_match_all($regex_mentiune, $string, $match);
foreach($match[1] as $mentiune)
{
$fetch_user = $sqli->query("SELECT COUNT(id) FROM tabela_utilizatori WHERE nume='$mentiune'");
$count = $fetch_user->fetch_array();
if($count[0] == "0")
{
$string = preg_replace($regex_mentiune, '$0', $string);
return($string);
} else {
$fetch_id = $sqli->query("SELECT id FROM tabela_utilizatori WHERE nume='$mentiune'");
$id = $fetch_id->fetch_array();
$user_id = $id[0];
preg_match_all($regex_mentiune, $string, $match);
foreach($match[1] as $mentiune)
{
$replace = "<a href=\"profil.php?id=$user_id\">$mentiune</a>";
$string = str_replace($mentiune, $replace, $string);
$string = str_replace('@', '', $string);
return($string);
}
}
}
return($string);
}