0

我已将此内容作为字符串存储在我的数据库中。列名是标题。我通过结果集循环检索此代码,但 php 代码在 html 代码中注释。我希望它应该执行的数据库中的任何 php 代码。字符串在花括号中给出如下:

{

“我们已经看到了如何通过将 Java 表达式放在字符序列<%=%>字符序列之间来将 Java 表达式嵌入到 JSP 页面中。但是仅仅通过将 Java 表达式放在 HTML 中进行大量编程是很困难的。

JSP 还允许您在 JSP 中编写 Java 代码块。

<?php if(!empty($chapter['path'])){ echo "<img src='chapter_images/".$chapter['path']."'>"; } ?> 

为此,您可以将 Java 代码放在<%%>字符之间(就像表达式一样。”

}

如果我没记错的话,这是可能的,但它是怎么回事?请有人帮助解决这个问题。

4

1 回答 1

0

The below example helps you in knowing it. First while loop is to execute the code on the page. Next while loop demonstrates that I had stored the php code into the database.

<?php
$con = mysql_connect("localhost", "root", "");
mysql_select_db("stackdb");

$result = mysql_query("select  * from demo");
$result1 = mysql_query("select  * from demo");
$d='';

while($row1 = mysql_fetch_array($result))
{
    $d = $row1[0];
    eval($d);
}
?>

<html>
<head></head>
<body>
    <h1>Demo application </h1>

    <?php
    while($row = mysql_fetch_array($result1))
    {
    ?>
        <p><?php echo($row[0]);?></p>
        <p><?php echo($row[1]);?></p>
    <?php 
    }
    ?>
</body>
</html>

I hope this will help you.

于 2013-09-11T06:31:57.923 回答