是否可以在HTML中打印PHP生成的结果? [关闭]

I am doing a program that does some calculations and in the end generates the result assign to the variable $result, the data is entered using a web form <form method = "POST" action = "file.php">

For example in <form> / web form the user can enter numbers using text fields and it submits to file.php and file.php calculates value and assign to $result variable.

Eg. $result = $value1 + $value2

And what I want is that in the HTML page (even if you have to reload the page) show something like:

"Your value equals 5"

Where 5 is what I left in $result.

What I want to know is that what is the convenient / right way of displaying the results in HTML page in PHP.

You can do it like this:

On your file.php

<?php 
     $value_1 = intval($_POST['value1']);
     $value_2 = intval($_POST['value2']);

     $result = $value_1 + $value_2;

     echo "Your value equals ".$result;

 ?>

You can echo it to your file.php

But if you want to redirect it to other html page with php you can create a session variable to save your $result just like this:

$_SESSION['result'] = $result; //the sum of the val_1 and val_2

Then just echo this to your other html page.

echo $_SESSION['result'];

Hope it will help.