把这个表达式放在这组引号里的最佳方式是什么


What is the best way to put this expression inside this set of quotes?

放置这个表达式的最佳方式是什么:

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' />
    ";
?>

方法2:

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

方法3:

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

更新:
方法4:我会使用方法4或5,因为用PHP处理会更快。这里的变化是我使用了单引号而不是双引号。

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

方法5:

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

我总是使用printf()

<?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." ' />";
?>