php variable in html no other way than: ?php echo $var; ?
There's the short tag version of your code, which is now completely acceptable to use despite antiquated recommendations otherwise:
<input type="hidden" name="type" value="<?= $var ?>" >
which (prior to PHP 5.4) requires short tags be enabled in your php configuration. It functions exactly as the code you typed; these lines are literally identical in their internal implementation:
<?= $var1, $var2 ?>
<?php echo $var1, $var2 ?>
That's about it for built-in solutions. There are plenty of 3rd party template libraries that make it easier to embed data in your output, smarty is a good place to start.
echo HTML with php variable
Try this.. run in your php enviroment
<html>
<head>
<style type="text/css">
p
{
text-align: center;
color: red;
}
</style>
</head>
<body>
<?php
$var = "Hello World";
echo "<p>The value of the variable is : " . $var . "</p>";
?>
</body>
</html>
How to display a php variable into html
Make your code more concise with jQuery:
(1) Add this in your <head>
:
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
(2) Create an element where you want the variable to be displayed, and give it an ID, e.g.:
<span id="printHere"></span>
(3) Add this in your JavaScript:
var duration="<?php echo $postduration ?>";
$('#printHere').html(duration);
For your PHP, try the following two options:
<?=$postduration?>
or...
<?php echo $postduration; ?>
PHP echo variable and html together
<?php
$variable = 'testing';
echo <span class="label-[variable]">[variable]</span>
?>
Should be
<?php
$variable = 'testing';
echo '<span class="label-' . $variable .'">' . $variable . '</span>';
?>
show php variable in html heading
use the following
<?php
$a="hi";
$prints =" <html>
<h1> $a</h1>
</html>";
echo"$prints";
?>
Related Topics
Pdo's Rowcount() Not Working on PHP 5.2.6+
Including PHP Variables in an External Js File
Setting $_Session Doesn't Work on Localhost Using Xampp
Split String into Equal Parts Using PHP
Can Mongodb and Its Drivers Preserve the Ordering of Document Elements
Set Multiple='False' in a Form in a Many to Many Relation Symfony2
Strip_Tags() Function Blacklist Rather Than Whitelist
PHP File_Get_Contents Ignoring Timeout
Check If Username Exists in MySQL Table via PHP
How to Read the Query String in PHP and HTML
Adding User Custom Field Value to Order Items Details
How to Stop Including a PHP File
Why Ob_Start() Must Come Ahead of Session_Start() to Work in PHP
PHP Remove/Fix Module Not Found or Already Loaded Warnings
PHP Post Limited to 1000 Variables
PHP - Make Multi-Dimensional Associative Array from a Delimited String