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. Quote 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 Quote 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]"; Quote 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 Quote 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); Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.