John Davidson

Beginner: Outputting php varibles inside html elements as values


I have a declared html file which is then used as an include statement inside a php file.

$social_width = "50";
$social_height = "50";


<a href=""><img src="instagram.png" width="<?php echo $social_width; ?>" height="<?php echo $social_height; ?>" style="padding-left:400px;"></a>

When I debug, that is to say, echo out the variables they do have the right set values. I tried using single and double quotes, escaping quotes but did not find the solution yet.

My Answer:
To output PHP variables inside HTML elements as values, you can use the following syntax:


Outputting PHP Variables


Your email address is:

In your PHP file, you can define the variables `$username` and `$email` before including the HTML file:

$username = "John Doe";
$email = "[email protected]";

When the PHP file is executed, the HTML file will be included and the PHP variables will be outputted inside the HTML elements as values.

Rate this post

3 of 5 based on 9414 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us