使用PHP修改HTML标记之间的文本

Let's say I have index.php:

 <p id="aid">Some text</p>
<?php
//SOME SCRIPT
?>

I want to do something like document.getElementById('aid').innerHTML = "Changed TEXT", but in PHP. To replace text. Is this possible, using PHP? If yes, how? Hope you understood me.

No.

document.getElementById('aid').innerHTML

is a Javascript code. It cannot be parsed by a PHP server.

What you could do is:

 <p id="aid"><?php
if(someCondition)
  echo "SOME SCRIPT";
else
  echo "Some text";
?></p>

As per your question, whether it is possible of not, then no, it is not possible to do it in php. There are different approaches, but for any text to change, using ONLY php, you will have to do reload the page, and update variable either using POST or GET method, or any other approach.

i'll show one example.

php code:

<?php
  $var = $_GET['var'];
?>

html would be:

<p><?php echo $var ?></p>
<a href="www.homeurl.com?var=new_value"> change var </a>

This is one way you can change the variable.

You can not modify the DOM once the HTTP response has been sent to the client/browser. That's impossible with PHP.

But, your question was a little unclear. When I first read it I assumed you wanted to change the content of HTML before the response is sent back. This is possible:

<?php
    $aidValues = [1, 2, 3, 4, 5];
?>
<p id="aid"><?= $aidValues[array_rand($aidValues)]; ?></p>

The text node of the p element will contain a random value. Replace this with whatever logic you require.