简体   繁体   中英

how put html+script inside the image.php file

I'm unable to combine these codes

put this html code

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

inside 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)
?>

Output expect

enter image description here

use include() or require() . It can load html file in php

eg

index.html :

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

include.php

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

result in include.php :

hello, world!

It will be working

<?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")
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM