开发者

PHP & HTMl Mix in a PHP $Var

开发者 https://www.devze.com 2022-12-15 04:29 出处:网络
Mixing html and php is simple: <? while($row): ?> <p><?=$row[\'name\'] ?></p> <?php endwhile; ?>

Mixing html and php is simple:

<? while($row): ?>
    <p><?=$row['name'] ?></p>
<?php endwhile; ?>

But how could i store html like this into a php variable? (Purposed syntax, but doesn't work)

<? $html = ?>
    <p>My 开发者_开发问答HTML!!</p>
<? ; ?>


This is how:

$html = <<< HTML
    <p>My HTML!!</p>
HTML;

That is know as php heredoc

Note: You should place closing heredoc keyword without any spaces or indentation.


You could use the heredoc syntax when declaring the string:

<?php
    $html = <<<HTML
    <p>My HTML!!</p>
HTML;
?>

This treats anything between the start <<<HTML (HTML is the identifier) and the end HTML as a string. Note that the closing identifier must be the first in a new line without any indention.

0

精彩评论

暂无评论...
验证码 换一张
取 消