Я только что создал систему 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>
Вместо:
$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']];
Вы можете использовать переменная-переменная :
echo $$_GET['404'];
хотя с массивом вам может потребоваться:
echo ${$_GET['404']};
http://sandbox.onlinephpfunctions.com/code/4f51e957806e803300dd58e892532e311a19a32a
Однако лучшим решением было бы сохранить переменные в массиве:
$images = ['a' => 'something.jpg', 'b' => . 'something-else.png']; echo $images[$_GET['404']];