Php 在条件运算符中添加html标记
我想在php中使用带有in条件运算符的frame标记,以检查特定字段是否有值。如果是,我想在frame src中打印值。我不想将值保留为空Php 在条件运算符中添加html标记,php,iframe,drupal-7,Php,Iframe,Drupal 7,我想在php中使用带有in条件运算符的frame标记,以检查特定字段是否有值。如果是,我想在frame src中打印值。我不想将值保留为空 <?php print (!empty($fields['field_perspective_video'])) ? echo '<iframe src="'.$fields['field_perspective_video']->content.'"></iframe>'; : ''; ?> 在上面
<?php print (!empty($fields['field_perspective_video'])) ?
echo '<iframe src="'.$fields['field_perspective_video']->content.'"></iframe>'; : ''; ?>
在上面的一行中,我“捕获了意外的回显”错误。我宁愿创建一个变量,然后在if中设置它的值,然后执行回显以打印带有或不带iframe的变量:
<?php
$auxVar = '';
print (!empty($fields['field_perspective_video'])) ?
$auxVar = '<iframe src="'.$fields['field_perspective_video']->content.'"></iframe>' : $auxVar = '';
echo $auxVar;
?>
如果已经使用了打印,则不需要echo
print (!empty($fields['field_perspective_video'])) ?
'<iframe src="'.$fields['field_perspective_video']->content.'"></iframe>' : '';
print(!empty($fields['field\u perspective\u video'])?
'' : '';
编辑并删除了意外符号,在这里您可以看到代码编译没有错误: