Skip to content

Standard scriptlets, jo <? ... ?> syntax ka upyog #4205

@mudassarmuz

Description

@mudassarmuz

Standard scriptlets, jo syntax ka upyog karte hain, code ko execute karte hain jiske liye explicit output nahi hota hai. Lekin, jaise ki is udaaharan mein dikhaaya gaya hai, scriptlet ke andar code ke parinaam bhi HTML code content ko prabhavit kar sakte hain.

Yeh hain kuchh tarah ke code jo aap scriptlet mein upyog kar sakte hain:

Variable Assignment

<?php 
 $name = "John Doe"; 
?>
<html>
 <body>
  <h1>Hello, <?php echo $name; ?>!</h1>
 </body>
</html>

Control Structures

<?php 
 $age = 25; 
?>
<html>
 <body>
  <?php if ($age >= 18) { ?>
   <p>You are an adult!</p>
  <?php } else { ?>
   <p>You are a minor!</p>
  <?php } ?>
 </body>
</html>

Function Calls

<?php 
 function greet($name) {
  return "Hello, $name!";
 }
?>
<html>
 <body>
  <h1><?php echo greet("John Doe"); ?></h1>
 </body>
</html>

Object Manipulation

<?php 
 $person = array("name" => "John Doe", "age" => 25); 
?>
<html>
 <body>
  <h1><?php echo $person["name"]; ?></h1>
  <p>Age: <?php echo $person["age"]; ?></p>
 </body>
</Html 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions