douye7033 2015-12-30 01:16
浏览 100
已采纳

html / php文件+ css内联问题

This is my php file, index.php

<html>
   <div id='hello'>Hello, <?php $name?>! How are you?</div>
</html>

This is my css file, index.css

<style>
   #hello {
       font-size: 36px;
       color: red;
       border: 1px solid red;
   }
</style>

I am trying to use the library https://github.com/tijsverkoyen/CssToInlineStyles to convert my index.php file to inline css. The problem is, it converts the closing php tag '?>' to '?&gt' for the closing tag. I know the library is targeting HTML and my file is a .php, but are there a way to stop the '>' tag from being converted to it's respective symbol '&gt'? If so, how?

  • 写回答

3条回答 默认 最新

  • dongzhi1822 2015-12-30 01:34
    关注

    For the what you posted, the short answer is no. At least not without tweaking the library (as you pointed out, it is intended for HTML files).

    If you really (really) need to do the "conversion" dynamically (as in "each time the page is requested") you can do that on the client side by manipulating the DOM with some JavaScript. (see here).

    If you need the conversion to be done only once and then leave the output file as a server resource you could use template pre-processing.

    I'm not sure of why you want to convert to inline css, perhaps if you explain a bit more we could point you in the right direction.

    G00d 1uck.

    [UPDATE] So the conversion should be dynamic. A way to go is (instead of using a PHP file that contains HTML code with embedded echoed PHP values) to put all html + PHP 'echoed' into a string variable and then inject the result as a stream (or as an actual temp file) to the converter, wait for the output and send it by email.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探