Insert an image into index.php file

Hi, how do I insert an image into my index.php file? As of now it looks like this:

<?php
echo (“Hello”);
?>

Many thanks,
Torsten

You insert images with php in much the same way you insert images with html.

If you are wanting to stay in php, echo the html code.


<?php
echo ' 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<img src="/images/image1.png" width="280" height="125" title="Logo of a company" alt="Logo of a company" />

</html>
';
?>

I left out a lot of the html code that should be on most pages.

If you just want to use a little php, you can just use short bits of php inserted where you need it.

Some html pages actually using the php include to create parts of the website that are repeated on many (or all) pages. If you want to include an image on every page, copy the code you use on your page and save it to a include folder besing sure to start and stop the code with the php start and stop tags.

Then locate the place you want the image to show on your webpage, and use code similar to this:
<?php include($_SERVER[‘DOCUMENT_ROOT’].“/include/logo.php”) ?>

If that was not what you are looking for, try restating your question.

The server will compile the php code , and send it along with your php file.

So you can just


<html><head><title><?php echo "cool title";?></title></head>
<body
<?php 
$image_url='https://www.google.com/intl/en_com/images/srpr/logo3w.png';
?>

<img src="<?php echo $image_url;?>">

<br><h1>Got me?</h1>

A php file can contain a combination of html, css and javascript. If your web page file name has a .php extension, the web page is first sent to the “php engine” on the web server where all the php code is run before sending the web page and any output from the php code down to the browser.

So depending where your image is coming from, inserting an image in your index.php could be as simple as

index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
        <title></title>
    </head>
    <body>
        <?php
        echo ("Hello");
        ?>
        <div>
            <img src="myPic.jpg" alt="myPic" />
        </div>
    </body>
</html>

Hey,

You can insert image in Index.php file by(<img src=“myPic.jpg”>) img src command.