0

我想创建一个 YouTube 视频列表,如教程。但是我不想为每个视频创建每个页面,我看到许多网站通过使用查询字符串来做到这一点,但我不知道如何使用它,谁能给我一个例子。

    ===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.....** 

?>

谢谢

4

4 回答 4

0

我建议您从索引页面传递一个实际的视频 ID,例如,

<a href="tutorial.php?id=OzHvVoUGTOM">First tutorial</a>

比你可以直接使用id到 YouTube 网址,

$id = $_GET['id'];
$videoLink = "http://www.youtube.com/watch?v=".$id;
于 2013-04-05T06:49:11.193 回答
0

像这样的东西?

<?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。

于 2013-04-05T06:52:30.527 回答
0

您可以为此使用过滤器功能;它还确保提供id的是一个整数值:

if (($id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE)) !== null) {
    // do stuff with $id
}

也可以看看:filter_input()

于 2013-04-05T06:53:13.820 回答
0

变量$_GET是一个数组,其中包含您通过 URL 传递的键和值,例如:

tutorial.php?id=12
tutorial.php?another_id=13

你可以抓住 12

$_GET['id']

和 13 由

$_GET['another_id']

看: http: //php.net/manual/en/reserved.variables.get.php

于 2013-04-05T06:54:59.620 回答