我正在尝试使用 javascript/jquery 显示 PHP 变量,但它显示的是“null”。
if(mysql_num_rows($checkBan) > 0){
$bannedDate = $checkBan['banLength'];
if(preg_match('/[0-9]/',$bannedDate)){
list($yyyy,$mm,$dd) = explode('-',$bannedDate);
$date = $mm."-".$dd."-".$yyyy;
}
//$date = "test"; when this is uncommented it appears in the alert so I know the json_encode is working fine
?>
<script type ="text/javascript">
var bannedUntil= <?php echo json_encode($date); ?>;
alert('Your account has been banned until ' + bannedUntil +'. Please contant an administrator if you believe this is an error');
</script>
<?
}
警报看起来很好,但bannedUntil 变量为空。但是,当取消注释第二个日期变量时,它会出现在警报中。它不是一个单独的函数,所以我不明白为什么范围会成为问题。