Heredoc this PHP-HTML

[亡魂溺海] 提交于 2019-12-11 13:44:09

问题


I'm trying to heredoc the following code:

<?php 
   //some php
   //some more php
   if (some condition) {
?>   
   <label>CMKS1<?php echo $CMKS1_CMKS2_space; ?>CMKS2</label>
   <input name="cmks1" type="text" class="base-cls <?php if ($err1) echo "err-cls"; ?>" />
   <input name="cmks2" type="text" class="base-cls <?php if ($err2) echo "err-cls"; ?>" />    
<?php
   }//if
   //some final php here
?>  

but I'm stuck on the $CMKS1_CMKS2_space variable on the label line and the 2 if conditional statements in input name cmks1 and cmks2. Is the heredoc format able to handle these gracefully? For example the label line in heredoc would look like this:

<label>CMKS1$CMKS1_CMKS2_spaceCMKS2</label>

or should I enforce an extra discretionary space:

<label>CMKS1 $CMKS1_CMKS2_space CMKS2</label>

As for the if conditional statements on the 2 input lines, I'm not even sure how to port these...

TIA


回答1:


Inside the heredoc, you can use this syntax to specify the correct variable names:

<label>CMKS1{$CMKS1_CMKS2_space}CMKS2</label>

Unfortunately, there is no way to add the conditional statements inside heredoc syntax.



来源:https://stackoverflow.com/questions/1552332/heredoc-this-php-html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!