开发者

Store inline HTML within variable in PHP

开发者 https://www.devze.com 2023-03-11 08:26 出处:网络
I was wondering, mostly because I think I\'ve seen it before somewhere, if it is possible to store HTML within a variable, something like the following (I know this makes no sense, it\'s just to clari

I was wondering, mostly because I think I've seen it before somewhere, if it is possible to store HTML within a variable, something like the following (I know this makes no sense, it's just to clarify my question):

<? $var = '开发者_StackOverflow社区 ?>
text goes here
<? '; ?>

And then $var would equal text goes here


You could do that using output buffering. Have a look at the examples at ob_get_contents() and ob_start().

<? ob_start(); ?>

All kinds of stuff, maybe some <?= "php"; ?> etc.

<? $var = ob_get_contents(); ?>


You may be thinking of the Heredoc syntax:

<?php
$var = <<<EOD
text goes here
EOD;
?>


Check out this facebook blog post on XHP, a language that allows XML literals within PHP code.

0

精彩评论

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