Enter Keyword Hear for Search This Blog

Friday, 22 June 2018

How Embedded Programming Works

How Embedded Programming Works

Before now, I’ve only mentioned that PHP code must be enclosed in the <?php and ?> PHP tags. Using tags to separate PHP code and HTML code within the same file allows programming code to be mixed directly with information that is going to be sent to the browser just as it is. This makes PHP an embedded programming language because PHP code is embedded directly in HTML code.

This concept is relatively new: Before languages like PHP, programs had no real need to display data using a structured formatting language as complex as HTML. Information displayed on the screen was usually just letters, numbers, and spaces, without many colors, sizes, or other formatting markups.

Since PHP was made for Web programming, it is intended to be used with HTML, which significantly increases the amount of information that has to be sent back to the browser. Not only does PHP have to send back the information the user sees, but also the markup tags required to format the information correctly.

To make the mixing of information and markup tags simpler, PHP code is embedded directly in the HTML page where the information is desired. The example at the beginning of this chapter demonstrates this concept quite clearly; the program is mostly regular HTML code, but PHP is also used to insert some information.

Embedded programming will make your job as a programmer much easier; you can add programming where you need it and use regular HTML the rest of the time. However, be sure to enclose your PHP code in PHP tags or your code will not be parsed, but rather displayed on the HTML page.

The following program provides another example of embedded programming :

<?php
/* File: hello_world.php – displays “Hello, World!” */
?>
<html>
<head><title>Hello, World!</title></head>
<body bgcolor=”white” text=”black”>
Hello,
<?php
// Send “World!” to the visitor’s browser
echo “World!”;
?>
</body>
</html>

When this file is accessed through a Web server, the PHP interpreter will process the file line by line from the top to bottom. Thus, the information before the opening PHP tag is sent to the browser, along with the result of the echo statement. The Web browser receives an HTML file that looks like this:

<html>
<head><title>Hello, World!</title></head>
<body bgcolor=”white” text=”black”>
Hello, World!
</body>
</html>

The browser then displays the file just as it would any other HTML file.

No comments:

Featured post

what is ajax?how to create ajax with php code

Ajax Introduction -  એજેક્સ નો ઉપીયોગ કરી ને તમે પેજ લોડ કાર્ય વિના બધી માહિતી મેળવી શકો.એજેક્સ થી તમે કોઈ પણ ડેટા ઝડપ થી મેળવી શકો છો...