2017-08-10 42 views
0

我無法將這些代碼結合內部如何把HTML +腳本image.php文件

把這個HTML代碼

<div id="time"></div> 
    <script> 

    function Timer() { 
     var dt=new Date() 
     document.getElementById('time').innerHTML=dt.getHours()+":"+dt.getMinutes()+":"+dt.getSeconds(); 
     setTimeout("Timer()",1000); 
    } 
    Timer(); 
    </script> 

內image.php

<?php 
header("Content-type: image/png"); 
$str1= " $_SERVER[REMOTE_ADDR]"; 
$str2= "**place code html**"; 
$image= imagecreate(200,40); 
$background = imagecolorallocate($image,255,255,255); 
$color= imagecolorallocate($image,0,0,0); 
imagefill($image,0,0,$background); 
imagestring($image,10,5,5,$str1,$color); 
imagestring($image,10,5,20,$str2,$color); 
imagepng($image) 
?> 

輸出預計

enter image description here

+0

從您的預期輸出圖像我只能猜測你想創建一個動態圖像顯示和IP地址和時間?要將JavaScript與'PHP'結合起來,您需要將'javascript'的輸出發送到'php',因爲'php'在任何客戶端語言(例如'javascript' – NewToJS

+0

)之前在服務器上運行,您是否可以幫助我? – tmmovie

+0

爲什麼不研究了一種使用PHP獲取客戶端時區/時間戳?這將節省嘗試要結合JavaScript來張貼到PHP來再創建圖像? – NewToJS

回答

0

使用include()require()。它可以在PHP

例如加載HTML文件

的index.html:

<div class="node">hello, world!</div> 

include.php

<?php 
    include("index.php"); 
?> 

結果include.php:

hello, world! 

將工作

<?php 
header("Content-type: image/png"); 
$str1= " $_SERVER[REMOTE_ADDR]"; 
$str2= "**place code html**"; 
$image= imagecreate(200,40); 
$background = imagecolorallocate($image,255,255,255); 
$color= imagecolorallocate($image,0,0,0); 
imagefill($image,0,0,$background); 
imagestring($image,10,5,5,$str1,$color); 
imagestring($image,10,5,20,$str2,$color); 
imagepng($image) 
include("image.html") 
?> 
+0

不顯示HTML – tmmovie