在PHP代码中嵌入多行警报框

时间:2014-01-19 17:53:55

标签: javascript php multiline

我想在JavaScript代码中嵌入一个JavaScript警告框,并希望文本报告变量值。以下代码给出了多行,但不允许我使用变量。

?>
<script type="text/javascript">
alert("Total size of all files too large.\nConsider uploading files in smaller sets.\nYou can append to existing sets.");
document.location.href="SomewhereElse.php";
</script>
<?php

以下代码允许我使用变量但不提供多行。

$Str="Total size cannot be not more than " . ini_get('post_max_size');
echo "<script type='text/javascript'>\n";
echo "alert('" . $Str . "');";
echo "</script>";

当我尝试此代码时,不会出现警告框。

    $Str="Unable to load (all of) these files because of their (total) size" .
    "\nPlease make the upload set conform to the following parameters";
    echo "<script type='text/javascript'>\n";
    echo "alert('" . $Str . "');";
    echo "</script>";

如果我离开\ n(在Please之前),我会收到警告框,但它不是多行的。我想知道\ n是否解除警报框。无论如何,如何获得带变量的多线警报框?

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

<?php

 $max_size = ini_get('post_max_size');
 echo '<script>';
 echo 'alert("Total size cannot be more than ' . $max_size . '!\nPlease make sure...");';
 echo '</script>';

?>