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

报告相同问题?