开发者

file_get_contents page does not support php

I am working with my php new site. Here I want to write an html page usi开发者_JAVA技巧ng php file write code. In this I used file_get_contents. E.g. see below

$page_old.="<table width='1051' border='0' cellspacing='0' cellpadding='0'>";
$page_old.="<tr><td height='50' class='tittle'>Test</td></tr>";
$page_old.="<tr><td class='content'>My content Body</td></tr></table></td></tr>";
$page_old.=file_get_contents('../contents/footer.php');     
fwrite($fp_old,$page_old);
fclose($fp_old);

My footer page contains some php code see below

<td colspan="4"><a href="../more-products.php?feat1_id=YlX>PdRf" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image49','','../images/Kluz_usa_s_over_18.jpg',1)"><img src="../images/Kluz_usa_s_18.jpg" name="Image49" width="276" height="162" border="0" alt="Universal Laser Systems VersaLASER " title="<?=$test_vra?>" ></a></td>

I want to assign the title, alt src value from a php variable. But the result is not correct. E.g. my title tag showing

How I display the actual content from that php variable

Thanks in advance


file_get_contents will give you the contents of the file as a string, not parse that file as executable code.

The easiest way to do what you want is to turn on output buffering, include that PHP file so that it's executed, then append the buffer to your $page_old variable.

$page_old.="<table width='1051' border='0' cellspacing='0' cellpadding='0'>";
$page_old.="<tr><td height='50' class='tittle'>Test</td></tr>";
$page_old.="<tr><td class='content'>My content Body</td></tr></table></td></tr>";

ob_start();
include('../contents/footer.php');
$output = ob_get_contents();
ob_end_clean();

$page_old .= $output;

file_put_contents('filename.html', $page_old);


file_get_contents returns a string with the HTML of the provided url.

If you want to use fwrite and fclose, you need to open footer.php with fopen.

But your question does not make sense to me. Do you want to overwrite footer.php with $page_old? If so, you could use file_put_contents and do a file_put_contents('../contents/footer.php', $page_old);.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜