使用查询字符串在PHP中创建视频列表?
我想创建一个类似YouTube视频教程的列表。 但我不想为每个视频创建每个页面,我看到很多网站都是通过使用查询字符串来实现的,但我不知道如何使用它。有人能给我举个例子吗使用查询字符串在PHP中创建视频列表?,php,Php,我想创建一个类似YouTube视频教程的列表。 但我不想为每个视频创建每个页面,我看到很多网站都是通过使用查询字符串来实现的,但我不知道如何使用它。有人能给我举个例子吗 ===index.php=== <html> <body <a href="tutorial.php?id=10">First tutorial</a> <a href="tutorial.php?id=11">Second tutorial</a>
===index.php===
<html>
<body
<a href="tutorial.php?id=10">First tutorial</a>
<a href="tutorial.php?id=11">Second tutorial</a>
<a href="tutorial.php?id=12">Third tutorial</a>
</body
</html>
===tutorial.php===
<?php
$id = $_GET['1'];
**//So how do I display a page and video here?
//How would it determine where is id=10, id=11, id=12.....**
?>
==index.php===
我建议您从索引页传递一个实际的视频id,比如
<a href="tutorial.php?id=OzHvVoUGTOM">First tutorial</a>
像这样的
<?php
$id = $_GET['id'];
//you should validate the $id to ensure it corresponds to a video that exists
echo ' ?>
<video width="320" height="240" controls>
<source src="video<?php echo $id; ?>.mp4" type="video/mp4" />
<source src="video<?php echo $id; ?>.ogg" type="video/ogg" />
Your browser does not support the video tag.
</video>
<?php '; ?>
视频文件名类似于video1.mp4
,数字是视频的id。您可以使用过滤功能;它还确保提供的id
是一个整数值:
if (($id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE)) !== null) {
// do stuff with $id
}
另请参见:变量$\u GET
是一个数组,包含通过URL传递的键和值,例如:
tutorial.php?id=12
tutorial.php?another_id=13
你可以坐12分钟
$_GET['id']
由
$_GET['another_id']
看:如果你问我们如何构建页面,你问的问题不对:)
$_GET['another_id']