How can we display the output directly to the browser?

Forums PHPHow can we display the output directly to the browser?
Staff asked 1 week ago

Answers (1)

Add Answer
Staff answered 1 week 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.


    $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.”


Select Categories