如何在PHP中将字符串存储为html代码?

时间:2015-05-29 07:53:07

标签: php html string

请指导我如何在php文件中存储一串与PHP代码混合的书面html或html?

例如我想通过php文件函数添加html代码,我如何存储将在我的新html文件中显示的字符串。

2 个答案:

答案 0 :(得分:1)

就像一个普通的字符串:

$htmlSnippet = "<div id=\"yourID\">the content of your div</div>";

或者您可以使用单引号:

$htmlSnippet = '<div id="yourID">the content of your div</div>';

答案 1 :(得分:0)

我想这就是你要找的东西。

 <?php

    $divId = 'main_div';

    echo myfun($divId);

    function myfun($divId ){
        $html = "<div id='".$divId."'> This is a html div </div>";
        $html .= "<input type='text' value='".$divId."'>";
        return $html;
    }

    ?>