PHP-如果某些参数通过,清除屏幕的短代码? [关闭]

Lets say I have a simple php index website page.

I have a need to clear the screen depending on when certain parameters are passed to the index page. The code that checks the passed parameters could appear anywhere in the index page.

If the parameter is not passed the page loads normally, if it is passed it clears/blanks the screen or alternatively pops a blank window to echo into.

I want to do it as efficiently as possible as a one-liner leading to my echo statement (if possible).

Couldn't you simply reference a tag in javascript to

<body></body>

and then set the innerhtml value from there?

For example, we can use a button that will use the

document.body.innerHTML

property to set the page to whatever we want like such . . .

document.body.innerHTML = 'cleared';

or . . .

<button name="btnClear" id="btnClearMe" onclick="document.body.innerHTML = 'cleared'" >Clear Page</button>

full code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body id="bdContent">
    <button name="btnClear" id="btnClearMe" onclick="document.body.innerHTML = 'cleared'" >Clear Page</button>
</body>
</html>

If I understand the question, you want to either have your php echo nothing, or echo the page, depending on some variable. If this is what you want, you can just put this at the top of your php

<?php
    if(condition){return;}
    //the rest of you page goes here

    ?>
<?php
if($_GET['parameter'] == 'blank'){
  echo '';
}else{
  echo 'something';
}
?>
  • mysite.com (this will show something)
  • mysite.com?parameter=blank (this will show nothing)