将PHP页面转换为静态HTML页面的最简单的方法 [英] Easiest way to convert a PHP page to static HTML page

查看:120
本文介绍了将PHP页面转换为静态HTML页面的最简单的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经管理了很多CSS样式的网页,以PHP格式写入静态HTML,以便将其嵌入到电子邮件中。要做到这一点,但为了实现这一点,我不得不将整个页面转换成一个字符串,然后将该字符串分配为电子邮件正文。该页面的布局看起来不如原来的那样好,因为我无法嵌入CSS。



这种方法有一些问题,如果需要进行任何更改对于页面的布局,我必须重做生成可嵌入页面的整个过程。



我想要一个更简单的方法,让我保持原始页面可编辑Dreamweaver可视化。

解决方案

可以使用输出缓冲区。如果您有一个html页面,例如:

 < html> 
< head>
< title> Blah< / title>
< / head>
< body>
这里有一些文本
< / body>
< / html>

然后,如果你放在html文件的顶部:

 <?php ob_start(); ?> 

在最后一个标签之后,放置:

 <?php 
$ string = ob_get_contents();

//做任何你需要做的html,保存到一个单独的文件,电子邮件它

ob_flush();
?>

这基本上意味着$ string变量将最终与页面的整个静态HTML在动态生成之后。然后,您可以在电子邮件中使用该字符串。虽然真的,html页面在电子邮件中的工作方式不一样,但您可能需要重新考虑这种方法。


I want to convert a web pages which is heavily CSS styled is written in PHP to static html so that I can embed it in an email.

I have managed to do this but for achieving this I had to convert the whole page into a string and then assign that string as email body. The layout of the page does not look as good as original as I have not been able embed CSS.

This approach has a few problems like if any changes have to be made to the layout of the page I have to redo the whole process for generating an embeddable page.

I want an easier way which will allow me to keep the original page editable in Dreamweaver visually.

解决方案

You can use output buffers. If you have an html page, such as:

   <html>
      <head>
         <title>Blah</title>
      </head>
      <body>
        Some text here
      </body>
   </html>

Then if you put, at the top of the html file:

<?php ob_start(); ?>

And right at the bottom, after the last tag, put:

<?php 
   $string = ob_get_contents(); 

   //do whatever you need to do to the html, save it to a seperate file, email it, etc

   ob_flush();
?>

What this basically means is that the $string variable will end up with the entire static html of the page, after it has been dynamically generated. You can then use that string in an email. Although really, html pages don't work exactly the same in emails, so you may want to rethink the approach.

这篇关于将PHP页面转换为静态HTML页面的最简单的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆