marcus Posted November 10, 2007 Share Posted November 10, 2007 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 More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 what is the contents of your $post variable Link to comment https://forums.phpfreaks.com/topic/76756-solved-using-a-function-in-preg_replace/#findComment-388676 Share on other sites More sharing options...
marcus Posted November 10, 2007 Author Share Posted November 10, 2007 Should that matter? $post = "[user=matt]"; Link to comment https://forums.phpfreaks.com/topic/76756-solved-using-a-function-in-preg_replace/#findComment-388683 Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 was just checking because I am trying the same thing out here and it seems to be working Link to comment https://forums.phpfreaks.com/topic/76756-solved-using-a-function-in-preg_replace/#findComment-388688 Share on other sites More sharing options...
rajivgonsalves Posted November 10, 2007 Share Posted November 10, 2007 this should work $post = preg_replace ("/\[user=(.*?)\]/eis","uname2('$1')",$post); Link to comment https://forums.phpfreaks.com/topic/76756-solved-using-a-function-in-preg_replace/#findComment-388691 Share on other sites More sharing options...
marcus Posted November 10, 2007 Author Share Posted November 10, 2007 Worked like a charm, tyvm. Link to comment https://forums.phpfreaks.com/topic/76756-solved-using-a-function-in-preg_replace/#findComment-388713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.