如何在另一个php标签中使用一个php标签中定义的变量?

I wrote a php page which has two php tags and one script tag inside it .

<?php
$value = $_GET['hash'];
?>
<script>
function execute(){
<?php
$readfile = file($value);
for ($k=0;$k<=count($readfile)-1;$k++){
$cmd = $readfile[$k];
echo $cmd;}
?>
}
</script>

I want to use $value inside another php tag ( like above it has the file I want to open ), but I am not able to do it.Is the scope of variable limited to one php tag ? if yes how can I solve this problem Please help

Your code works perfectly. The variables in one PHP tag is accessible from all other tags, unless you define them inside a PHP function.

The reason you are not seeing the echo on the screen is because the echo prints to the Javascript function.

If you view the source of the generated page, the file contents will be there.

Try this:

function execute(){
    <?php
    $readfile = file($value);
    for ($k=0;$k<=count($readfile)-1;$k++){
        $cmd = $readfile[$k];
    ?>
        alert( <?php echo $cmd; ?> );
    <?php
    }
    ?>
}

execute();

if $value is a get then you don't need to access it as a file, it should just be a short string.

just above line 7 (the one with $readfile = file... type:

echo "alert(The hash value is: ".$value.")";

This will make an alert display (as it is in a script tag) p.s you should have in your opening tag