PHP Escaping From HTML

Definition and Usage

PHP file can have mixed content with code within tags embedded in a HTML document. Code outside tags is ignored by the parser, leaving it to be interpreted by client browser. A HTML document can have multiple blocks of PHP, each inside tags.

Syntax

HTML block

HTML block

HTML block

Every time opening PHP tag is encountered, parser starts rendering the output to the client until closing tag is reached. If code consusts of conditional statement, th parser determines which block to be skipped.

Again till another opening tag comes, everything is treated as HTML leaving the browser to process the same.

PHP Version

This description is applicable to all versions of PHP.

Following example shows PHP code embedded in HTML

Example



Hello World

Hello world again

Output

This will produce following result ?

Hello World
Hello World in PHP
Hello world again
Hello World again in PHP

Example using mixed HTML and PHP code

Example


Using conditional statement

=50): ?>

Result:pass

Result:Fail

Output

This will produce following result ?

Using conditional statement
Result:Fail

change marks to 60 and run again Using conditional statement Result:pass

Updated on: 2020-09-19T14:16:46+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements