Preg 替换为 mysql
好的,这就是我所拥有的,但每当我这样做时,我都会返回数据库的第一条记录:
<?php
function getInfo($id,$slot){
if(!$id){ return '<b>Error</b> Id Not Returned. Please contact [email protected] 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);
?>
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 [email protected] 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);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很惊讶你得到了任何返回的东西......你的 preg_replace 模式应该给你一个错误(你没有转义一些括号)。但无论如何,您不能像这样将捕获的组传递给您的函数。您必须使用“e”模式修饰符(请参阅 preg_replace 手册中的示例#4
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