HomeLanguagesHow to display string values within a table using PHP ?

How to display string values within a table using PHP ?

A table is an arrangement of data in rows and columns, or possibly in a more complex structure. Tables are widely used in communication, research, and data analysis.

  • Tables are useful for various tasks such as presenting text information and numerical data.
  • Tables can be used to compare two or more items in the tabular form layout.
  • Tables are used to create databases.

Approach: Use HTML table elements inside PHP echo to print the string values in a table. We can write HTML tags inside a PHP script to display the output rendered as an HTML component.

PHP code:

PHP




<?php
  
// Declaration of strings
$var1 = "Geeksforneveropen";
$var2 = "Priyank";
   
// Display HTML table using PHP echo
// Use $variable_name to use a string
// in code
echo "<table border=1 cellspacing=1 cellpadding=1>
    <tr> 
       <td><font color=green>$var1</font></td>
       <td>is best learning platform</td>
    </tr>
    <tr> 
        <td><font color=green>Written by</font></td>
        <td>$var2</td>
    </tr>
</table>";
?>


Output:

<table border=1 cellspacing=1 cellpadding=1>
    <tr> 
        <td>
            <font color=green>
                Geeksforneveropen
            </font>
        </td> 
        <td>
            is best learning platform
        </td>
    </tr>
    <tr> 
        <td>
            <font color=green>
                Written by
            </font>
        </td> 
        <td>
            Priyank
        </td>
    </tr>
</table>

If we run this code on a local server then the output will display in form of a table.

RELATED ARTICLES

Most Popular

Dominic
32548 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6924 POSTS0 COMMENTS
Nicole Veronica
12039 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12150 POSTS0 COMMENTS
Shaida Kate Naidoo
7060 POSTS0 COMMENTS
Ted Musemwa
7302 POSTS0 COMMENTS
Thapelo Manthata
7018 POSTS0 COMMENTS
Umr Jansen
7006 POSTS0 COMMENTS