简体   繁体   English

在MySQL数据库表中插入PHP Echo值

[英]Insert PHP Echo Value in MySQL Database Table

I have a database driven website (dynamic pages) but the content is stored in static files that are included in my pages. 我有一个数据库驱动的网站(动态页面),但内容存储在我的页面中包含的静态文件中。 I want to scrap these text files and put the content in a database table, but I don't know how to deal with PHP code in the content. 我想废弃这些文本文件并将内容放在数据库表中,但我不知道如何在内容中处理PHP代码。

For example, consider the following text: 例如,请考虑以下文本:

<p>You can learn more at <a href="<?php echo $MySite1; ?>">this website</a>.</p>

$MySite1 might echo <a href="wwww.mysite1.com"> , but if I put it into a database table, it just displays as plain text. $MySite1可能会回显<a href="wwww.mysite1.com"> ,但如果我把它放入数据库表中,它只会显示为纯文本。

So does anyone know how I could modify a query like the one below so that PHP code in content stored in field AI. 所以有人知道如何修改下面的查询,以便在内容AI中存储内容中的PHP代码。 Article will display as PHP code? 文章将显示为PHP代码? In other words, I'd like visitors to see www.mysite1.com , not <?php echo $MySite1; ?> 换句话说,我希望访客看到www.mysite1.com ,而不是<?php echo $MySite1; ?> <?php echo $MySite1; ?> . <?php echo $MySite1; ?>

Thanks. 谢谢。

  $Topics = mysql_fetch_assoc(mysql_query("SELECT ZT.N, ZT.URL, ZT.Title, ZT.Subtitle, ZT.Parent, ZT.Live, AI.URL, AI.Article
  FROM gz_topics ZT
  LEFT JOIN gz_articles_topics_intro AI ON AI.URL = ZT.URL
  WHERE ZT.URL = '$MyURL' AND ZT.Live = 1"));

You can use eval() function ( http://nl.php.net/manual/en/function.eval.php ). 您可以使用eval()函数( http://nl.php.net/manual/en/function.eval.php )。 Very dangerous as is shown in that linked page. 非常危险,如链接页面所示。

If you planning to use str_replace... More elegant solution could be just saving your template with %s,and using printf with the arguments needed... 如果您打算使用str_replace ...更优雅的解决方案可能只是使用%s保存模板,并使用带有所需参数的printf ...

really depends on the usage... 真的取决于用法......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM