从MySQL数据库内部调用PHP变量 [英] Calling PHP variables from inside a MySQL Database

查看:80
本文介绍了从MySQL数据库内部调用PHP变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究CMS系统,该系统可直接根据保存在MySQL数据库中的信息来构建网站。

I'm currently in the middle of working on a CMS system that builds the website straight from information saved in a MySQL database.

这是我遇到的问题:


  • 在CMS内部,用户输入模板编码

  • 站点的前端(frontend.php)调用存储布局的变量($ template_header)

  • 前端还通过从数据库中提取菜单代码来创建变量$ menu_code,该菜单代码也通过CMS进行存储

  • 在模板代码中,此变量必须有一个中断,当它是由frontend.php运行时。

  • Inside the CMS the user enters coding for a template
  • the frontend of the site (frontend.php) calls the variable where the layout is stored ($template_header)
  • The frontend also creates the variable $menu_code by pulling the menu code from the database, which was also stored via the CMS
  • Inside of the template code, there has to be a break for this variable, when it is run by frontend.php it will be picked up.

这是我一直在尝试的事情:

This is what I've been trying:

frontend.php内部:

inside frontend.php:

echo $template_header;

在$ template_header内:

inside of $template_header:

<tr><td><center>'.$menu_code.'</center></td></tr>

在IE中运行frontend.php时的外观:

What it should look like when frontend.php is run in the IE:

<tr><td><center><script>rest of menu coding in here</script></center></td></tr>

运行时的外观:

<tr><td><center>'.$menu_code.'</center></td></tr>

它像文本一样显示。这可能是一个简单的问题,但是在此项目的紧迫期限内,任何帮助将不胜感激,并且任何建议都将不胜感激。谢谢

it displays it like text. It's probably a simple problem but any help would be much appreciated, on a tight deadline with this project and any advice would be greatly appreciated. Thanks

推荐答案

如果我对您的理解正确,那么简单的替换就可以解决问题:

A simple replace would do the trick if I understand you correctly:

$template_data = "<tr><td><center>{%REPLACE_WITH_CONTENT%}</center></td></tr>";
$template_data = str_replace("{%REPLACE_WITH_CONTENT%}", $menu_code, $template_data);

这篇关于从MySQL数据库内部调用PHP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆