您的问题已经在我们代码库的其他地方得到解决......
取自我们的 WebApplication.php 文件:
/**
* Log a message to the javascript console
*
* @param $msg
*/
public function logToConsole($msg)
{
if (defined('CONSOLE_LOGGING_ENABLED') && CONSOLE_LOGGING_ENABLED)
{
static $last = null;
static $first = null;
static $inGroup = false;
static $count = 0;
$decimals = 5;
if ($first == null)
{
$first = microtime(true);
$timeSinceFirst = str_repeat(' ', $decimals) . ' 0';
}
$timeSinceFirst = !isset($timeSinceFirst)
? number_format(microtime(true) - $first, $decimals, '.', ' ')
: $timeSinceFirst;
$timeSinceLast = $last === null
? str_repeat(' ', $decimals) . ' 0'
: number_format(microtime(true) - $last, $decimals, '.', ' ');
$args = func_get_args();
if (count($args) > 1)
{
$msg = call_user_func_array('sprintf', $args);
}
$this->registerStartupScript(
sprintf("console.log('%s');",
sprintf('[%s][%s] ', $timeSinceFirst, $timeSinceLast) .
str_replace("\n", "'+String.fromCharCode(13)+'", addslashes($msg))));
$last = microtime(true);
}
}
您感兴趣的是:
str_replace("\n", "'+String.fromCharCode(13)+'", addslashes($msg))
请注意,在您的问题中sprintf
,您忘记了 str_replace...