我可以编辑脚本以根据网址/字段输入重新运行吗?

I have a script that gets a streams link based on the external html page.

Is there a way to have one script and a resourced page with links to all the external links or do I need to have an individual page per request?

In other words, can I do this

example.com/videos.php?v=1234

or must I use

example.com/eachVideoPage.php

Here is the script I use to get the link.

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/xmpegURL");


?>
<?php
ob_start(); // ensures anything dumped out will be caught
$html = file_get_contents("http://example.com/aVideoPage.html");

preg_match_all(
    '/(http:\/\/[^"].*?\.mp4)[",].*?/s',

    $html,
    $posts, // will contain the article data
    PREG_SET_ORDER // formats data into an array of posts
);

foreach ($posts as $post) {
    $link = $post[1];


// clear out the output buffer
while (ob_get_status())
{
    ob_end_clean();
}

// no redirect
header("Location: $link");
}

?>

Assuming all you want to do is change the file_get_contents() URL It should be as simple as:

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/xmpegURL");

$vid = htmlspecialchars($_GET["v"]);

ob_start(); // ensures anything dumped out will be caught
$html = file_get_contents("http://example.com/$vid/aVideoPage.html");

preg_match_all(
    '/(http:\/\/[^"].*?\.mp4)[",].*?/s',

    $html,
    $posts, // will contain the article data
    PREG_SET_ORDER // formats data into an array of posts
);

foreach ($posts as $post) {
    $link = $post[1];


// clear out the output buffer
while (ob_get_status())
{
    ob_end_clean();
}

// no redirect
header("Location: $link");
}

?>

Updates: $vid = htmlspecialchars($_GET["v"]);

Using _GET will take the URL Query parameters and do whatever you want with them. In this case a basic value assignment looking for ?v=123 in the URL. ($vid === '123')

It is worth mentioning that you should add some code to handle cases where ?v does not exists, or contains malicious input (depending on who uses it)

Then just reuse the value in the URL you want to call:

$html = file_get_contents("http://example.com/$vid/aVideoPage.html");

Update after comments

In order to call another site with a query string you can simply append it to the URL:

$html = file_get_contents("http://example.com/aVideoPage.html?v=$vid");

This will depend entirely on the remote site you are calling however. .html files usually won't do anything with query strings unless there is JavaScript in the code that uses it. But generally if you can browse to the remote URL with ?v=1234 in the URL and it selects the right video, then the above should also work.