如何在netbeans 8.0.1中的html代码中使用php代码?

时间:2014-11-02 10:55:28

标签: php html5 .htaccess netbeans

我可以创建一个新的php项目,但我想创建我创建的html5项目,我希望也使用php代码。

除了下载和使用netbeans,我还下载并使用xampp。 运行xampp之后,我点击了apache上的开始。

现在要浏览我的测试网站:

http://localhost:8383/HTML5Application1/index.html

这是我为测试而下载的免费模板。 我的网站中我试图在html文件中使用php的页面是:

http://localhost:8383/HTML5Application1/images%20slideshow.html

slideshow.html文件内容如下所示:

<?php 
$pattern="(\.jpg$)|(\.png$)|(\.jpeg$)|(\.gif$) |(\.Gif$)"; //valid image extensions 
$files = array(); 
$curimage=0; 
if($handle = opendir($"http://newsxpressmedia.com/files/radar-simulation-files")) { 
    while(false !== ($file = readdir($handle))){ 
        if(eregi($pattern, $file)){ //if this file is a valid image 
            //Output it as a JavaScript array element 
            $files[] = $file; 
            $curimage++; 
        } 
    } 
    closedir($handle); 
} 
?> 

<!DOCTYPE html>

<html>
   <head>
      <title>change picture</title>

      <link rel="stylesheet" type="text/css" href="/css/result-light.css">

  <style type='text/css'>
    #Timer_Countdown{
    background:black;
    color:yellow;
    font-weight:bold;
    text-align:center;
}
  </style>

      <script type = "text/javascript">

          function displayNextImage() {
              x = (x === images.length - 1) ? 0 : x + 1;
              document.getElementById("img").src = images[x];
          }

          function displayPreviousImage() {
              x = (x <= 0) ? images.length - 1 : x - 1;
              document.getElementById("img").src = images[x];
          }

//$json = json_encode($files);
//json = <?php echo $json; ?>
//var images = JSON.parse(json);
//var images = <?=json_encode($files)?>;
var images = [];
var x = -1; 
var swap_hours = 0;
var swap_minutes = 0;
var swap_seconds = 5;

var down_counter_hours;
var down_counter_minutes;
var down_counter_seconds;

function initTimer() {

    down_counter_hours = swap_hours;
    down_counter_minutes = swap_minutes;
    down_counter_seconds = swap_seconds;
    counter = setInterval(switcher, 1000);
}

function restartCounter() {
        down_counter_hours = swap_hours;
        down_counter_minutes = swap_minutes;
        down_counter_seconds = swap_seconds;
}

function switcher() {
    down_counter_seconds--;
    if (down_counter_hours <= 0 && down_counter_minutes <= 0 && down_counter_seconds <= 0) {
        swapColor();
        restartCounter();
    }
    if (down_counter_seconds <= 0 && down_counter_minutes > 0) {
        down_counter_seconds = 60;
        down_counter_minutes--;
    }
    if (down_counter_minutes <= 0 && down_counter_hours > 0) {
        down_counter_minutes = 60;
        down_counter_hours--;
    }

    document.getElementById("Timer_Countdown").innerText =        down_counter_hours+":"+down_counter_minutes+":"+down_counter_seconds;
}

function swapColor() {
    displayNextImage();
}

      </script>
      <div id="div_hours" class="div_box"></div>
      <div id="div_minutes" class="div_box"></div>
      <div id="div_seconds" class="div_box"></div>
      <div id="div_switcher" class="div_box"></div>
   </head>

   <body onload = "initTimer()">
       <div id="Timer_Countdown">&nbsp;</div>
       <img id="img" src="http://newsxpressmedia.com/files/theme/radar000005.Gif">
       <button onclick="displayPreviousImage(); restartCounter()">Previous</button>
       <button onclick="displayNextImage(); restartCounter()">Next</button>
   </body>
</html>

在顶部我有一个以<?php开头并以?>结尾的php代码

但是netbeans显示在左边的行附近:<?php错误:

  

可能的原因:尝试在HTML中使用XML处理指令。   (HTML不支持XML处理指令。)

我不想创建php项目但是使用html5项目并使用php代码。 所以现在我认为xampp应该到位并且netbeans应该使用它在安装xampp后自动创建的.htaccess。

有没有办法在netbeans 8.0.1中的HTML5项目中使用PHP代码?

我现在正在本地进行测试。

0 个答案:

没有答案