是否可以将PHP与HTML“Value”属性一起使用

Im working on a checkout page and ive used a text document and some PHP to be able to change the price at one place (the textdocument) and it will change over the whole website on its own. but i got a problem where i need to insert the price into a HTML Value attribute but i cant get it to work with the PHP script. im mainly going to use it for a normal paypal button.

<input type="hidden" name="amount" value="<?$file = ("textfile.txt");
    $read = fopen($file, "r");
    $data = fread($read, filesize($file));
    echo $data;
    fclose($read);?>">

Here is the code ive tried but it doesnt work and i just get an error when clicking the button: "The link you have used to enter the PayPal system contains an incorrectly formatted item amount."

Is there anyway to solve this?

You can make your code a lot simpler by just using file_get_contents() like so:

<input type="hidden" name="amount" value="<?php echo file_get_contents('textfile.txt'); ?>">

Note that the PHP tags are also changed. Short tags might be disabled so you shouldn't rely on them.

Without knowing the contents of your textfile.txt, I can't be sure, but make sure it does not contain anything to designate the currency type ($, USD, etc). It should only contain a float value like 5.02