Site icon T4Tutorials.com

How to use HTML tags in PHP echo?

How to HTML tags in PHP echo?

Example 1: This example demonstrates that how HTML tags can be used in  PHP echo to display the result.

<?php  
    $name = "T4Tutorials"; 
    echo "<h1>Hello User, </h1> <p>Welcome to {$name}</p>"; 
?>

Example 2: This example demonstrates that how HTML tags can be used in  PHP echo to display the result by Separating HTML from PHP.

<?php 
    $number = 5; 
    for ($i = 1; $i <= 10; $i++) {  
?> 
   
    <p><?= $number ?> * <?= $i ?> 
        = <?= $number * $i ?></p> 
   
<?php 
    } 
?>

Example 3: We can use <<< heredoc to print the html. <<< must be followed by an identifier and line break.

<<<GFG
// HTML Markup
GFG;

<?php 
echo <<<GFG 
    <h1>T4Tutorials</h1> 
    <p>I am in heredoc with identifier 'GFG' .</p> 
GFG; 
?>

Example 3: How PHP echo in HTML tables using database MySQL and Mysqli table?

<table border 1px>
<center><h3>Welcome: <?php echo "<tr><td>".$row['name']."</td></tr>"; ?> </h3></center>
<center><h3>Welcome: <?php echo "<tr><td>".$row['Email']."</td></tr>"; ?> </h3></center>
   
</table>
Exit mobile version