开发者

How to combine conditional check with php heredoc syntax?

i use a heredoc syntax to populate some content for output.

While preparing these content i need to check for some condi开发者_StackOverflow社区tions to decide whether to add them or not.

While i tried that, it shows errors..

 echo <<<END_HTML
<div class="menu_form_body">
<table style="font-family:arial; font-size:12px; color:#ffffff;">
    <tr>
        <td colspan="2" align="center"><center><b>{$title}</b></center></td>
    </tr>
    <tr>
        <td>{$filter[$key]['street']}<br/>
            {$filter[$key]['city']}, {$filter[$key]['state']}<br/>
            {$filter[$key]['zip']}<br/>
        </td>
        <td nowrap>{$filter[$key]['phone']}<br/>
            {$filter[$key]['email']} // here i need to check for some condition
        </td>
    </tr>
END_HTML;

so i tried

....
<td nowrap>{$filter[$key]['phone']}<br/>
END_HTML;
if($filter[$key]['display_email']!='No'){
echo <<<END_HTML
{$filter[$key]['email']}
END_HTML;
}
echo <<<END_HTML
....
...
END_HTML;

what may be the issue?


I am not even sure if this is possible inside a heredoc statement. But besides that it's just plain ugly and unreadable. You do not want to do this.

Why do you need a condition inside your heredoc? You could do the condition evaluation before you execute the heredoc statement.

$condition = output condition $filter[$key]['email']

echo <<<END_HTML
  {$condition}
END_HTML;


Make sure none of your END_HTML; statements are indented.

Also, why do you have to use heredoc for this? Why not just do something like:

if($filter[$key]['display_email']!='No'){
echo "{$filter[$key]["email"]}";
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜