如何处理这个HTML代码作为单引号和双引号引用PHP? [英] How to deal with this HTML code echoed with PHP which as both single and double quotes?

查看:190
本文介绍了如何处理这个HTML代码作为单引号和双引号引用PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定这是否是一种更清晰的写法,但我认为在这里没有问题:

I'm not sure if this is a cleaner way of writing this, but I think I don't have problems here:

<?php switch ( $meta_box['type'] ) {
    case 'textarea':
        echo '<textarea name="<?php echo $meta_box[ 'name' ]; ?>">
        <?php echo htmlspecialchars( $data[ $meta_box[ 'name' ] ] ); ?>
        </textarea>'
        break;

这更复杂,因为要回显的元素有单引号和双引号:

Here is more complicated, since the elements to be echoed have single and double quotes:

默认值:

default:

       echo "<input type="text" name="<?php echo $meta_box[ 'name' ]; ?>"
           value="<?php echo htmlspecialchars( $data[ $meta_box[ 'name' ] ] ); ?>"" /><?php
    }

这段代码是什么?

这是完整的switch语句:

This is the full switch statement:

<?php switch ( $meta_box['type'] ) {
    case 'textarea':
        echo '<textarea name="<?php echo $meta_box[ 'name' ]; ?>">
        <?php echo htmlspecialchars( $data[ $meta_box[ 'name' ] ] ); ?>
        </textarea>'
        break;
    default:
       echo "<input type="text" name="<?php echo $meta_box[ 'name' ]; ?>"
           value="<?php echo htmlspecialchars( $data[ $meta_box[ 'name' ] ] ); ?>"" /><?php
    }
}

?>


推荐答案

如果您真的想输出 em> PHP代码:

If you really want to output PHP code:

<?php switch ( $meta_box['type'] ) {
    case 'textarea':
        echo '<textarea name="<?=$meta_box[\'name\']?'.'>">
        <?=htmlspecialchars( $data[ $meta_box[ \'name\' ] ] ) ?'.'>
        </textarea>';
        break;
    default:
       echo '<input type="text" name="<?=$meta_box[ \'name\' ] ?'.'>"
           value="<?=htmlspecialchars( $data[ $meta_box[ \'name\' ] ] ) ?'.'>">';

?>

否则这对我更有意义:

Otherwise this makes more sense to me:

<?php switch ( $meta_box['type'] ) {
    case 'textarea':
        echo '<textarea name="'.$meta_box['name'].'>">'.
          htmlspecialchars( $data[ $meta_box['name'] ] ).
        '</textarea>';
        break;
    default:
       echo '<input type="text" name="'.$meta_box[ 'name' ].'" '.
         'value="'.htmlspecialchars( $data[ $meta_box[ 'name' ] ] ).'">';
}

?>

但是我猜测 $ data [$ meta_box ['name']] 数组索引不正确。

But I guess that $data[$meta_box['name']] array index isn't correct either.

这篇关于如何处理这个HTML代码作为单引号和双引号引用PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆