在 Heredoc 中插入 PHP 代码到 select 好的选项

Insert PHP code in Heredoc to select the good option

您好,目前正在处理一个页面以获取与我的数据库对应的表单。 我希望好的选项 'TYPE' 得到对应于 $client['CLT_type']

的 selected

这是我的实际代码的样子(以及我测试的内容) 但我收到此错误:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in 24

24 是我的 $select 行

if($client = $requeteClt->fetch()) {

        $select = "<?php if($client['CLT_type']==2) echo 'selected'; ?>";

        $page->appendContent(<<<HTML
            <div id='res' height='800px'></div>
            <form id='form' name='form' method='POST' action='modifierClientScript.php' style='width:100%;'>
                <h2 style="text-align:center;">Modification du client {$client['CLT_libelle']}</h2>
                <p>
                    <label for='montant'>Nom :</label>
                    <input type='text' value='{$client['CLT_libelle']}' name='nom' id='nom'>
                    <span class="error" id="nomErr"></span>
                </p>
                <p>
                <label for='type'>Segmentation Client :</label>
                    <SELECT name='type' id='type'>
                        <optgroup label="Publics">
                            <OPTION value='1'>Etat
                            <OPTION value='2' {$select}>Collectivité
                            <OPTION value='3'>Entreprise publique
                        <optgroup label="Privés">
                            <OPTION value='4'>Entreprise de service
                            <OPTION value='5'>Entreprise industrielle
                            <OPTION value='6'>Autres
                    </SELECT>
                </p><br/>

                <p><br/>
                    <input type='button' name='submit' id='submit' value='Modifier le client'>
                </p>
            </form>
HTML
);

那么是否可以在 Heredoc 中添加 PHP 代码,或者我是否必须通过其他方式管理我的页面? 谢谢

为了您的错误修正。

$select = ($client['CLT_type']==2) ? 'selected' : null;

切勿在 <?php 个标签内使用 <?php 个标签。