Preg Replace with mysql
Okay so heres what I have but whenever I do this, I am returned with the first record of the database:
<?php
function getInfo($id,$slot){
if(!$id){ return '<b>Error</b> Id Not Returned. Please开发者_运维知识库 contact support@site.com for more information.'; }
$mm = mysql_query("SELECT * FROM `users` WHERE `id`='".$id."'");
$mma = mysql_fetch_assoc($mm);
$p = $mma[$slot];
return $p;
//return $id; <- Debug (Returns ID given)
}
$post = preg_replace("/\[CallName]([^]]+)\[\/CallName\]/", getInfo('\\1',"fullname"), $post);
?>
I'm surprised you're getting anything returned...your preg_replace pattern should be giving you an error (you aren't escaping some of your brackets). But anyways, you can't pass a captured group to your function like that. You have to use the "e" pattern modifier (look at example #4 in the preg_replace manual
精彩评论