我刚刚制作了一个404系统,它有两种功能: ?404 - 将加载随机模因。 ?404 =(a-u) - 将指定一个模因。
目前我必须在选择器部分指定所有这些,有没有办法从中获取查询字符串和echo变量?
<center>
<br>
<?php
$a = '<img src="https://img-9gag-fun.9cache.com/photo/aAxQ9Bd_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
$b = '<img src="https://img-9gag-fun.9cache.com/photo/aPjmGrB_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
$c = '<img src="https://img-9gag-fun.9cache.com/photo/a2oMpY1_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
$d = '<img src="https://img-9gag-fun.9cache.com/photo/anM7Djq_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
$e = '<img src="https://img-9gag-fun.9cache.com/photo/awrmNLB_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
$f = '<img src="https://img-9gag-fun.9cache.com/photo/aMAvmGM_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
$g = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/avOWw3Z_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/avOWw3Z_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/avOWw3Z_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/avOWw3Z_460svwm.webm" type="video/webm"></video>';
$h = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/a0Kognd_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/a0Kognd_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/a0Kognd_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/a0Kognd_460svwm.webm" type="video/webm"></video>';
$i = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/agXQ9Wq_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/agXQ9Wq_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/agXQ9Wq_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/agXQ9Wq_460svwm.webm" type="video/webm"></video>';
$j = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/aAxQ232_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/aAxQ232_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/aAxQ232_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/aAxQ232_460svwm.webm" type="video/webm"></video>';
$k = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/anMOZZo_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/anMOZZo_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/anMOZZo_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/anMOZZo_460svwm.webm" type="video/webm"></video>';
$l = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/aExMKDn_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/aExMKDn_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/aExMKDn_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/aExMKDn_460svwm.webm" type="video/webm"></video>';
$m = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/aAxQAPZ_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/aAxQAPZ_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/aAxQAPZ_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/aAxQAPZ_460svwm.webm" type="video/webm"></video>';
$n = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/aZ3n9zz_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/aZ3n9zz_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/aZ3n9zz_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/aZ3n9zz_460svwm.webm" type="video/webm"></video>';
$o = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/agXQRo6_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/agXQRo6_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/agXQRo6_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/agXQRo6_460svwm.webm" type="video/webm"></video>';
$p = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/a0KXb7Q_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/a0KXb7Q_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/a0KXb7Q_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/a0KXb7Q_460svwm.webm" type="video/webm"></video>';
$r = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/aLjz2LV_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/aLjz2LV_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/aLjz2LV_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/aLjz2LV_460svwm.webm" type="video/webm"></video>';
$r = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/a0KXYvZ_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/a0KXYvZ_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/a0KXYvZ_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/a0KXYvZ_460svwm.webm" type="video/webm"></video>';
$s = '<video preload="auto" poster="https://img-9gag-fun.9cache.com/photo/arg34Yd_460swp.webp" loop="loop" autoplay="autoplay" style="max-height: 500px; min-height: 500px; max-width: 500px;"><source src="https://img-9gag-fun.9cache.com/photo/arg34Yd_460svvp9.webm" type="video/webm"><source src="https://img-9gag-fun.9cache.com/photo/arg34Yd_460sv.mp4" type="video/mp4"><source src="https://img-9gag-fun.9cache.com/photo/arg34Yd_460svwm.webm" type="video/webm"></video>';
$t = '<iframe height="500" width="890" src="https://www.youtube.com/embed/a3nPG9JpoLg?rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0" allow="autoplay encrypted-media"></iframe> ';
if ($_GET['404'] == 'a') { echo $a; }
else if ($_GET['404'] == 'b') { echo $b; }
else if ($_GET['404'] == 'c') { echo $c; }
else if ($_GET['404'] == 'd') { echo $d; }
else if ($_GET['404'] == 'e') { echo $e; }
else if ($_GET['404'] == 'f') { echo $f; }
else if ($_GET['404'] == 'g') { echo $g; }
else if ($_GET['404'] == 'h') { echo $h; }
else if ($_GET['404'] == 'i') { echo $i; }
else if ($_GET['404'] == 'j') { echo $j; }
else if ($_GET['404'] == 'k') { echo $k; }
else if ($_GET['404'] == 'k') { echo $l; }
else if ($_GET['404'] == 'm') { echo $m; }
else if ($_GET['404'] == 'n') { echo $n; }
else if ($_GET['404'] == 'o') { echo $o; }
else if ($_GET['404'] == 'p') { echo $p; }
else if ($_GET['404'] == 'q') { echo $q; }
else if ($_GET['404'] == 'r') { echo $r; }
else if ($_GET['404'] == 's') { echo $s; }
else if ($_GET['404'] == 't') { echo $t; }
else {
$error = range('a', 't');
$random_error = array_rand($error);
echo $$error[$random_error];
}
?>
<h1>You dun goofed</h1>
<?php echo 'Error code: '. $_SERVER['QUERY_STRING']; ?>
</center>
<style>
body { overflow-y: hidden; }
#content { height: 1000px; }
</style>
答案 0 :(得分:3)
而不是:
$a = '<img src="https://img-9gag-fun.9cache.com/photo/aAxQ9Bd_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
$b = '<img src="https://img-9gag-fun.9cache.com/photo/aPjmGrB_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
$c = '<img src="https://img-9gag-fun.9cache.com/photo/a2oMpY1_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">';
等,你可以使用一个关联数组,如:
$memes = array(
'a' => '<img src="https://img-9gag-fun.9cache.com/photo/aAxQ9Bd_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">',
'b' => '<img src="https://img-9gag-fun.9cache.com/photo/aPjmGrB_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">',
'c' => '<img src="https://img-9gag-fun.9cache.com/photo/a2oMpY1_460s.jpg" style="max-height: 500px; min-height: 500px; max-width: 500px;">',
);
然后,您可以使用查询字符串值来获取基于该键的成员,例如:
echo $memes[$_GET['404']];
答案 1 :(得分:0)
您可以使用variable-variable:
echo $$_GET['404'];
虽然它可能是一个数组:
echo ${$_GET['404']};
http://sandbox.onlinephpfunctions.com/code/4f51e957806e803300dd58e892532e311a19a32a
更好的解决方案是将变量保存在数组中:
$images = ['a' => 'something.jpg', 'b' => . 'something-else.png'];
echo $images[$_GET['404']];