简体   繁体   English

我如何将php嵌入此处的文档样式?

[英]How can i embed php inside here doc style?

how can i embed php inside here doc style? 我如何在此处doc样式中嵌入php?

for example : 例如 :

<?php
echo <<<EOF
<input type="radio" <?php echo "selected"; ?>>
EOF;
?>

I want to perform above task, suggest code for this or any alternative. 我想执行以上任务,为此或任何替代方法建议代码。

The problem is that heredoc IS php code. 问题是,heredoc是php代码。 Consider this example: 考虑以下示例:

$sel = ' selected';
$var = <<<EOF
<input type="radio"${sel}>
EOF;
echo $var;

You'll notice that we don't need the < ?php open or ?> close tags to achieve this. 您会注意到,我们不需要<?php open或?> close标记即可实现此目的。 This is because the interpreter parses and interprets all of this. 这是因为解释器解析并解释了所有这些。 You are over thinking it. 您想得太多了。

MORE EXPLAINATION: In the end, everything inside a heredoc statement needs to evaluate to a string. 更多说明:最后,heredoc语句中的所有内容都必须求值为字符串。 The way to accomplish what you want is to use php to create strings with everything in them BEFORE you get to the heredoc command. 完成所需操作的方法是在到达heredoc命令之前,使用php创建包含所有内容的字符串。 That way the heredoc command can do the only thing it knows how to do which is to create longer strings from shorter ones. 这样,heredoc命令可以做的唯一事情就是从较短的字符串创建较长的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM