【问题标题】:an error happened when change the color of tables in php printf function在 php printf 函数中更改表格颜色时发生错误
【发布时间】:2016-11-08 03:02:07
【问题描述】:

我想使用 printf 函数更改 php 文件中表格文本的颜色。 但是当我使用这两种方法时,我失败了。 你能告诉我怎么会这样吗? 我怎样才能改变颜色? 方法一:

 <?php   
      printf('<tr>');  
      printf('<td><font color='red'>abc</font></td>');  
      printf('</tr>');
  ?>

方法B:

 <?php
  printf('<tr>');
  printf('<td style="color:red">abc</td>');
  printf('</tr>');
 ?>

PS:原问题:(这是代码的一部分)

 $userrow = mysql_fetch_array($userqueryresult);
            $thisuserid = $userrow[0];
            $user_type=$userrow[1];

printf("   <td valign = 'center'  width='40%%'>
<a href='show_user.php?u=%d'>
<font color='red'>%s</font></a></td>\n",$thisuserid, $key);

事实上,当我使用 color="red" 时,它失败了,而 color='red',它起作用了。 " " " 和 " ' " 之间有什么区别吗? 但正如 Julie Pelletier 所说,“abc”它奏效了。 这也是“ ”。

【问题讨论】:

    标签: php html printf html-table


    【解决方案1】:

    这两种情况都缺少&lt;table&gt; 标记,该标记告诉浏览器将内容作为表格处理。

    第一个错误很突出,引号中没有引用red。您可以使用不同的引号轻松修复它:

    <?php   
        printf('<table><tr>');  
        printf('<td><font color="red">abc</font></td>');  
        printf('</tr></table>');
    

    对于第二个,只要你把它放在&lt;table&gt; 中,它就可以正常工作:

    <?php
        printf('<table><tr>');
        printf('<td style="color:red">abc</td>');
        printf('</tr></table>');
    

    如果必须在字符串中包含引号,则必须使用不同类型的引号('")或在它们前面加上反斜杠(\)。

    【讨论】:

    • 谢谢,很抱歉用这么低的问题打断你。但原来的问题不是这样的。我编辑了它。能再看一遍吗?
    • 您的主要问题是您没有意识到如果您将所有类型的引号都放在其他引号中,解释器无法猜测您在做什么。作为程序员,您必须确保引号易于理解。
    • 我想我已经意识到我错在哪里了。谢谢你!
    猜你喜欢
    • 1970-01-01
    • 2012-07-08
    • 2018-10-25
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多