Jump to content

[SOLVED] Using a Function in preg_replace


marcus

Recommended Posts

I have:

 

$post = preg_replace ("/\[user=(.*?)\]/is",uname2("$1"),$post);

 

and the function

 

function uname2($value){
$sql = "SELECT * FROM `users` WHERE `username`='$value'";
$res = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_assoc($res);

return "<a href=\"/profiles.php?user={$row['username']}\" style=\"text-decoration:none;\"><img src=\"/images/users/ui_{$row['level']}.png\" alt=\"\" border=\"0\"> {$row['username']}</a>\n";
}

 

My result: �

 

Basically I suppose the actually value inside the uname2 function isn't necessarily being passed.

Link to comment
https://forums.phpfreaks.com/topic/76756-solved-using-a-function-in-preg_replace/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.