2012-04-16 102 views
-1

目前,我有一個形象的HTML語句,我想將其添加到HTML如何使用php在html變量內添加html語句?

$html=file_get_contents('../template/'.$html); 
    $img="<img src='http://localhost/fyp/ga/test.php?=$ga'>"; 
    file_put_contents($html,$img); 

然而裏面,這導致從瀏覽器的警告,也將後追加IMG語句,所以如何將其添加內部使用PHP?謝謝。

$img="<img src='http://localhost/fyp/ga/test.php?=$ga'>"; 

它得到這樣一個警告:

Warning: file_put_contents(<p> <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> <!-- Facebook sharing information tags --></p> <p> <meta content="*|MC:SUBJECT|*" property="og:title" /> </p> <p> <title></title> <style type="text/css"> /* Client-specific Styles */ #outlook a{padding:0;} /* Force Outlook to provide a "view in browser" button. */ body{width:100% !important;} .ReadMsgBody{width:100%;} .ExternalClass{width:100%;} /* Force Hotmail to display emails at full width */ body{-webkit-text-size-adjust:none;} /* Prevent Webkit platforms from changing default text sizes. */ /* Reset Styles */ body{margin:0; padding:0;} img{border:0; height:auto; line-height:100%; outline:none; text-decoration:none;} table td{border-collapse:collapse;} #backgroundTable{height:100% !important; margin:0; padding:0; width:100% !important;} in C:\xampp\htdocs\fyp\mail\send.php on line 47 
+0

你用'file_get_contents'打開的文件是什麼樣的?您需要在該文件中添加圖像的位置? – kba 2012-04-16 20:16:25

+0

它是一個html文件。我需要將其添加到謝謝 – user782104 2012-04-16 20:18:46

回答

0

我會假設你有你的HTML中的佔位符。例如{IMAGE},比你簡單地用這個佔位符代替

<?php 
    $html = str_replace("{IMAGE}","<img src='http://localhost/fyp/ga/test.php?=".$ga."'>",$html); 
?>