zyMacro zyMacro - 4 months ago 14
HTML Question

an error happened when change the color of tables in php printf function

I want to change the color of text of the table in php file using printf function.
But when I used this two method , I failed.
Can you tell me how could that happen?
And how can I manage to change the color?
method A:

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


method B:

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

Answer

Both cases are missing the <table> tag which tells the browser to process the content as a table.

The first error stands out with the quotes leaving red unquoted. You can easily fix it by using different quotes:

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

For the second one, it works as is as long as you put it in a <table>:

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