我怎么把这个HTML写成php

时间:2014-01-02 22:12:26

标签: php html variables

所有这一切都需要在我的循环中,所以我不知道我是否可以打破它(不认为我可以)但我需要PHP将其作为HTML读取。

$movieDetails = 
<header class="masthead" role="banner">
        <div class="logo-container">
    <a class="logo" href="">Movie Details</a>
        </div>
</header>
        <div class="bubble-container">
            <div class="speech-bubble speech-bubble-top">
    Text that goes into the bubble
            </div> 
        </div>

2 个答案:

答案 0 :(得分:3)

您只需关闭PHP标记即可呈现将显示为HTML的文本。

<?php
foreach($movies as $movie) {
?>
   <div>
     <?php echo htmlspecialchars($movie); ?>
  </div>
<?php
}
?>

答案 1 :(得分:2)

$movieDetails = <<<HTML
<header class="masthead" role="banner">
        <div class="logo-container">
    <a class="logo" href="">Movie Details</a>
        </div>
</header>
        <div class="bubble-container">
            <div class="speech-bubble speech-bubble-top">
    Text that goes into the bubble
            </div> 
        </div>
HTML;

echo $movieDetails;

http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc