Embedding PHP in HTML pages - AJAX

PHP statements are embedded into HTML documents by surroundingthe PHP statements with <?php and ?> tags. Anything between such tags is evaluated by the web server and replaced with appropriate HTML code, prior to the page being served to the browser.

You can have as many sets of <?php and ?> tags in your page as you want.

Outputting HTML from PHP
Several PHP commands can help you write text and HTML code directly into your page. Perhaps the simplest is the echo command:

echo “I wrote this line using PHP”;

The preceding statement simply places “I wrote this line using PHP” into the HTML document at precisely the place where the PHP statement occurs.

Listing shows the source code of a PHP file to print Hello World in the browser window.

Printing Hello World in PHP

Note that in this script, the output string also contains some HTML tags, <h1> and </h1>. As the PHP statements are executed by the web server before serving the page to us, these tags are written into the document’s HTML along with the “Hello World” text and evaluated by our browser along with all other HTML markup in the document. Figure shows the browser displaying our “Hello World” page.

If we ask the browser to show us the source of this page, it displays the following code, in which we can see that the PHP elements have been completely evaluated by the web server, which has inserted the relevant HTML into the page:

"Hello World" in PHP

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

AJAX Topics