如何在 echo 中间使用 if else 语句

How to use an if else statement in the middle of an echo

我得到 Parse error: syntax error, unexpected 'if' (T_IF), expecting ',' or ';' in 是针对这一行的 if ($meta == '') 。有人可以提供一些指导,以便我的 if else 语句在此回声中起作用吗?谢谢!!!

    echo '<tr>
            <th><label for="twitter_embed">Twitter Embed</label></th>
            <td><textarea name="twitter_embed" id="twitter_embed" cols="60" rows="4">'
             if ($meta ==  '') 
              { get_option('my_option_name');
               }else{ 
                .$meta. ;
                 }'</textarea>
            <span class="description">Use to embed tweets on your post.</span></td>
            </tr>';

    echo '</table>';
}

get_option 适用于 wordpress。请有人帮忙解决 echo?

中的 if - else 语句

您可以改用三元运算符:http://php.net/manual/en/language.operators.comparison.php

<?php
  echo '<tr>
        <th><label for="twitter_embed">Twitter Embed</label></th>
        <td><textarea name="twitter_embed" id="twitter_embed" cols="60" rows="4">'. 
        ($meta ==  '') ? get_option('my_option_name') : $meta 
        . '</textarea>
        <span class="description">Use to embed tweets on your post.</span></td>
        </tr>';
?>