Echo Image Tag With Source And Its Method Using PHP

admin_img Posted By Bajarangi soft , Posted On 16-09-2020

echo an image by using php code

echo an image with php

 

  • echo is a language construct,not function
  • no need to use parentheses with it.
  • to use more than one parameter, it is required to use parenthesis.

PHP echo statement can be used to display the string, multi-line strings, escaping characters, variable, array, etc and we can also echo image to escape any single or double quotes inside of the string container if they match what you're using to echo out the image.

For example:
echo " ";

echo "<img src='" . $file_path . "' alt='am_rabbit'>";//within double quotes 
or
<img src='<?php echo $file_path ?>' alt='am_rabbit'>//within single quotes
 

Complete code to echo image in php

<!DOCTYPE html>
<html>
<head>
    <title>how do i echo an image with PHP</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
    <br>
    <br>
    <div class="text-center">
        <h1>echo an image with PHP</h1>
    </div>
    <br>
    <br>
    <div class="well">
        <?php
        $file_path = 'image/Rabbit.jpg';
        echo "<img src='" . $file_path . "' alt='error'>";
        ?>
        <img src='<?php echo $file_path ?>' alt='error'>
    </div>
    <br>
</div>
</body>
</html>

Related Post