PHP echo image to the browser
To get an image displayed on the browser using PHP, you can echo an <img> tag as follows:
echo '<img src="my-picture.png" alt="My image" />';
You need to replace my-picture.png with your actual picture name.
If the picture is not located in the same path as the PHP file, you need to write the right path.
Keep in mind that you need to use a different quote symbol then the one you use in the echo statement.
If you use single quotes for the echo statement, then use double quotes to avoid unexpected identifier error.
See the example below:
echo '<img src="my-picture.png" alt="My image" />';
// or
echo "<img src='my-picture.png' alt='My image' />";
You need to choose one of the two styles above and make it consistent on all your PHP files.
And that’s how you echo an image using PHP 😉
More PHP tutorials
See allPHP
PHP form validation basic example
Dec 22, 2022
PHP
PHP validate email address (with code examples)
Dec 22, 2022
PHP
How to redirect using PHP with code examples
Dec 22, 2022
PHP
Handling form data using PHP (GET and POST)
Dec 21, 2022
PHP
How to fix Wordpress PHP error missing MySQL extension
Dec 21, 2022