How can we display the output directly to the browser?

Forums PHPHow can we display the output directly to the browser?
Staff asked 3 years ago

Answers (1)

Add Answer
Staff answered 3 years ago

PHP echo or print statements are commonly used to display content on your webpage. They both do the same function. An echo and print statement generates output that is sent to your browser, which the browser interprets as HTML.

In this case, an interviewer might look into different options for showing PHP output in your browser.

<?=1+2 ?>

In scenarios where we merely want to return something as an output, we can receive the output using the syntax above, which makes entering the code a lot faster.

<?php 

    $a  = strtoupper("Hello,");

    $a .= " Welcome";
  
?>

<?=$a;  ?>

// Just try out this example
<?=1+10 ?>

We’ve done variable initialization (added a value to a variable) and then concatenated the same variable with another string, “Welcome,” so we only utilized the short-hand syntax to output the value of the variable in the next step.

This is an example of another technique to deliver output to a browser using PHP.

Warning: “We do not recommend writing your own code in this manner because some PHP versions do not support it. It’s, therefore, safer to write your echo statement completely.”

Subscribe

Select Categories