Thus far we have only looked at PHP as a standalone code. However, one of the main reasons PHP is useful as a web programming language is that it can be blended with html. This allows for hyrbid code that can take the results of a method or function, and display it in a web browser
It is important to keep in mind the differences between the two languages, as doing so will help you know what to change or modify when it comes time to edit your webpage. As a reminder, HTML is a markup language, and should only be used to render and format text and media. PHP is a programming language that should be used to make decisions on what text and media the html will display,. The two languages complement each other, and neither should be used as a replacement for the other.
With that in mid, there are two methods to go about blending the two languages. The first is to write have a HTML code with pieces of inserted within it.
<html>
<title>HTML and PHP</title>
<body>
<h1>Best Friends for life</h1>
<?php
//PHP CODE
?>
<b>HTML <3 PHP</b>
<?php
//MORE PHP CODE
?>
</body>
</html>
Notice that the PHP code is completely separated by start and close PHP tags, and there exists no HTML within the PHP. However, the HTML tags are not concerned with excluding PHP.
In other words, there is no HTML in the PHP. But there's PHP in the HTML.
This is the preferred method for integrating the two languages, especially for content heavy and complicated web pages. However, there is still a place for the integration technique demonstrated in the next blog post.