Php 将此表达式放入这组引号中的最佳方式是什么?

Php 将此表达式放入这组引号中的最佳方式是什么?,php,quotes,ternary-operator,Php,Quotes,Ternary Operator,用什么方式表达这个表达方式最好: echo isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '' 在此参数内: <?php echo " <input type='text' value=' *INSERT EXPRESSION* ' /> "; ?> 最简单的方法 <?php $exp = isset($GLOBALS['_url']) ? htmls

用什么方式表达这个表达方式最好:

echo isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : ''
在此参数内:

<?php
    echo "
    <input type='text' value=' *INSERT EXPRESSION* ' />
    ";
?>

最简单的方法

<?php
    $exp = isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '';

    echo "<input type='text' value=' $exp ' />";
?>

大概是这样的吧

<?php
    echo "
    <input type='text' value='" . 
        (isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '') . 
    "' />";
?>
以下是几种方法:

方法1:

<?php
    $expression = isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '';

    echo "
    <input type='text' value='$expression' />
    ";
?>
我总是使用

试试这个

<?php
    define('URL',isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '');
    echo "<input type='text' value=' ".URL." ' />";
?>

使用单引号属性值时,需要设置
ENT_QUOTES
标志以获得
的编码。您只需复制两个答案并粘贴为新答案:)干得好……)你们在我的回答中击败了我:(
<?php
    echo "
    <input type='text' value='" . isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '' . "' />
    ";
?>
<?php
    echo '
    <input type="text" value="' . isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '' . '" />
    ';
?>
<?php
    $expression = isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '';

    echo '
    <input type="text" value="' . $expression . '" />
    ';
?>
<?php

    printf("\n<input type='text' value='%s' />\n", isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '');

?>
<?php
    define('URL',isset($GLOBALS['_url']) ? htmlspecialchars($GLOBALS['_url']) : '');
    echo "<input type='text' value=' ".URL." ' />";
?>