I have read on many sites and documents saying like php is embedded in html. This is ok to understand but this statement is bit confusing for me.
If i have .html file and if i used php code for eg. following line:
<h1> <?php echo "This is PHP"; ?> </h1>
It wont work. But if i used same line of code in .php file it outputs the result.
So my confusion is if we are putting php code in .html file it is not giving results but still we are saying php is embedded in html.
Why cant we say html embedded in php and not php is embedded in html?
Now this line also outputs the same if it is used in .php file
<?php echo "<h1> This is PHP </h1>"; ?>
<h1> <?php echo "This is PHP "; ?> </h1>
Now here the file is .php so we can say we are putting html code in .php file, so if i say html is embedded in php is it right or wrong?
I would say this distinction is not right and not wrong, it's just useless...
You write a .php file, with some php code and some html inside.
Web server parses your file, interprets and executes php code, combines it with html, and produces an html page, which is sent to the requesting browser.
Thant's it... :-)
It depends on your server configurations if you want .html files to be treated as an php file(if it not already does) add this on your .htaccess
file
<FilesMatch "\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
Now these is an example of PHP in HTML
<input type="text" name="<?php echo $name;?>" value="<?php echo $value;?>"/>
And this is the example of HTML inside PHP
<?php echo "<input type=\"text\" name=\"$name\" value=\"$value\"/>";
You can not say html is embedded in php only if it is inside .php file it depends on your code and not your file extension .