2015-12-30 01:16
浏览 89

html / php文件+ css内联问题

This is my php file, index.php

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

This is my css file, index.css

   #hello {
       font-size: 36px;
       color: red;
       border: 1px solid red;

I am trying to use the library 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?

图片转代码服务由CSDN问答提供 功能建议


 &lt  ; html&gt; 
&lt; div id ='hello'&gt;您好,&lt;?php $ name?&gt;! 你好吗?&lt; / div&gt; 
&lt; / html&gt; 

这是我的css文件,index.css < pre> &lt; style&gt; #hello { font-size:36px; color:red; border:1px solid red; } &lt; / style&gt;

我正在尝试使用该库 tijsverkoyen / CssToInlineStyles 将我的index.php文件转换为内联css。 问题是,它转换关闭的php标签'?&gt;' 为结束标记添加'?&amp; gt'。 我知道该库的目标是HTML,我的文件是.php,但有没有办法阻止'&gt; '标记被转换为它的相应符号'&amp; gt < /代码>'? 如果是这样,怎么样?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongzhi1822
    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.

    点赞 评论
  • duansha7025
    duansha7025 2015-12-30 01:22

    No, it is (as it should) escaping those characters for you. Your css files should never contain html.

    Remove the <style></style> tags and it should work. You only need those if you're putting css into your html.

    点赞 评论
  • drd2551
    drd2551 2015-12-30 01:23

    The index.css should contain only:

    #hello {
      font-size: 36px;
      color: red;
      border: 1px solid red;

    The <style> is a HTML tag and it should not come in a .css file. If you have them inside your .css file, the whole file will not work.

    点赞 评论