2014-01-19 54 views
0

我想將一個JavaScript警告框嵌入到php代碼中,並希望文本報告變量值。下面的代碼給出了多行,但不支持我使用變量。在php代碼中嵌入多行警告框

?> 
<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(在請求之前),但它不是多行的,我會得到一個警告框。我想知道\ n是否取消了警告框。無論如何,我如何獲得帶變量的多行警報框?

回答

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>'; 

?>