PHP Embedding
Embedding PHP in Different Web Pages
Although it is Possible to Write down and run Standalone Hypertext Preprocessor (PHP) applications, Most Hypertext Preprocessor(PHP) code is Embedded in HTML or XML files. This is, in spite of Everything, why it Became created within the First Place. Processing such Files Entails Changing each Chunk of Hypertext Preprocessor(PHP) Source code with the Output It Produces whilst Finished.
Because a Single or Separate file Includes PHP and non-Hypertext Preprocessor (PHP) supply code, we want a way to Discover the Regions of PHP code to be carried out. PHP affords 4 exceptional methods to try this.
As you may see, the Primary, and Desired, Approach looks as if XML. The Second Technique looks like SGML. The Third Method is look like Based totally on ASP tags. The fourth Approach makes use of the usual HTML <script> tag; this makes it clean to edit pages with enabled PHP using a Regular HTML editor.
1. Short-open (SGML-style) tags
Quick or Short-Open tags look like this...
<?...?>
also other Example is
<? echo "Hello, how r u"; ?>
Quick tags are, as one Might Expect, the Shortest Choice You have to do one in every of Two matters to enable PHP to recognize the tags −
- Pick out the --allow-short-tags configuration alternative when you're constructing Hypertext Preprocessor(PHP).
- Set the Short_Open_tag setting in your Hypertext Preprocessor(PHP).Ini file to on. This Selection Need to be Disabled to Parse XML with Hypertext Preprocessor(PHP) due to the Fact the Identical Syntax is used for XML tags.
2. XML Style
Because of the arrival of the Extensible (XML) Markup Language and (XHTML) the migration of HTML to an XML language , the presently preferred approach for embedding Hypertext Preprocessor(PHP) makes use of XML-compliant tags to indicate Hypertext Preprocessor(PHP) instructions.
Coming up with tags to Demark Hypertext Preprocessor(PHP) instructions in XML changed into easy, due to the fact XML permits the definition of new tags. To use this fashion, surround your php code with <?Php and ?>. The Entirety among those Markers is Interpreted as Hypertext Preprocessor(PHP), and the whole thing out of doors the markers isn't. Although it isn't always essential to encompass spaces among the markers and the enclosed text, doing so improves clarity. As an example, to get PHP to print "Hello, world", you Could Insert the Subsequent Line in an Internet web page:
<?Php echo "Hello, world"; ?>
The Semicolon in this code at the Assertion is elective , because the end of the Block also Forces the give up of the Expression. Embedded in a whole HTML Document, this seems like:
<!Doctype>
<html>
<head>
<title>this is my first Hypertext Preprocessor(PHP) application!</title>
</head>
<body>
<p>
appearance, ma! It is my first Hypertext Preprocessor(PHP) application:<br />
<?Php echo "Hello, Allien"; ?><br />
How cool is that?
</p>
</body>
</html>
Of course, this isn't always very exciting—we ought to have Accomplished it without php. The real fee of Hypertext Preprocessor(PHP) comes while we Positioned Dynamic Data from Resources Consisting of Databases and form values into the web page. It's for a later Chapter, Even though. Let's get again to our "hi there, global" instance. When a consumer visits this web page and Perspectives its source, it looks as if this...
<!Doctype >
<html>
<head>
<title>this is my First practice PHP program!</title>
</head>
<body>
<p>
look, ma! It is my first practice Hypertext Preprocessor(PHP) programm:<br />
Hello, world!<br />
How cool is that?
</p>
</body>
</html>
Notice that there's no hint of the PHP source code from the unique file. The user sees only its output.
Additionally be aware that we switched between PHP and non-Hypertext Preprocessor(PHP), all within the space of a single line. PHP instructions can be placed Everywhere in a Record, even Within Legitimate HTML tags. As an example...
<input type="text" name="first_name"
value="<?php echo "Rasmus"; ?>" />
while Hypertext Preprocessor(PHP) is finished with this text, it'll read...
<input type="text" name="first_name"
value="Rasmus" />
The PHP code that is Within the Opening and Closing Markers does now not have to be at the Equal line. If the Final Marker of a Hypertext Preprocessor(PHP) Instruction is the Last thing on a line, the line Spoil following the last tag is Removed as Properly. Consequently, we can replace the Hypertext Preprocessor(PHP) Commands Inside the "HELLO, WORLD" instance with..
<?Php
echo "Hello, world"; ?>
<br />
with out a change inside the resulting HTML.
3. Active Server Pages(ASP)-Style Tags
ASP is Much Old but Still use for Making Dynamic webpages, also ASP is a Microsoft Technology,
Active Server Pages-ASP style tags Mimic the Tags used by Energetic Server Pages to Delineate code blocks. ASP-fashion tags look like this...
<%...%>
ASP run in a web server is a program.
to Apply ASP-style tags, you will Need to set the Configuration Alternative on Your Hypertext Preprocessor(PHP).Ini Report.
4. HTML Script Tags
HTML Script tags Appear to be this...
<script language="PHP">...</script>"
Comments
Post a Comment