在从URL显示之前替换PHP上的文本文件

在从URL显示之前替换PHP上的文本文件,php,text,Php,Text,我有一个GoldIPTV.m3u 以及显示GoldIPTV.m3u的get.php 我用了这个: <?php $file = 'GoldIPTV.m3u'; if (file_exists ($file)) { header ('Content-Description: File Transfer'); header ('Content-Type: application/octet-stream'); header ('Conte

我有一个GoldIPTV.m3u 以及显示GoldIPTV.m3u的get.php

我用了这个:

<?php
$file = 'GoldIPTV.m3u';

if     (file_exists    ($file)) {
    header    ('Content-Description: File Transfer');
    header    ('Content-Type: application/octet-stream');
    header    ('Content-Disposition: attachment; filename=     "'.basename    ($file).'"');
    header    ('Expires: 0');
    header    ('Cache-Control: must-revalidate');
    header    ('Pragma: public');
    header    ('Content-Length: ' . filesize($file));
    readfile   ($file);
    exit;
}



?>

好的。听起来你好像有你的档案

#EXTINF:-1,Channel 1
rtmp://cdn1.domain.com/iptv/ch2?code=key
#EXTINF:-1,Channel 2
rtmp://cdn1.domain.com/iptv/ch3?code=key
#EXTINF:-1,Channel 3
rtmp://cdn1.domain.com/iptv/ch4?code=key
当你加载

/get.php?key=112233445566

您希望替换该文件中的
。对吗

如果是,请尝试:

$string = file_get_contents('location');
echo nl2br(str_replace('code=key', 'code=' . $_GET['key'], $string));

用户可以使用这种方法操纵站点上的内容,因此要小心。如果
不是文本,则需要使用正则表达式。如果该参数/值的情况可能不同,请使用。

好的。听起来你好像有你的档案

#EXTINF:-1,Channel 1
rtmp://cdn1.domain.com/iptv/ch2?code=key
#EXTINF:-1,Channel 2
rtmp://cdn1.domain.com/iptv/ch3?code=key
#EXTINF:-1,Channel 3
rtmp://cdn1.domain.com/iptv/ch4?code=key
当你加载

/get.php?key=112233445566

您希望替换该文件中的
。对吗

如果是,请尝试:

$string = file_get_contents('location');
echo nl2br(str_replace('code=key', 'code=' . $_GET['key'], $string));

用户可以使用这种方法操纵站点上的内容,因此要小心。如果
不是文本,则需要使用正则表达式。如果该参数/值的情况可能不同,请使用。

键是否在所有链接中都是一致的静态值?
是这样的吗:/get.php?code=key
是一整行吗?你能发布3行吗?如果每个链接的键都是相同的,你可以通过php读入并替换字符串。否则,您将需要单独处理每一个。是的,它在所有链接上都是静态的,而您只需执行
str\u replace('code=key','code=123456',$string)
。\f:-1,通道1rtmp://cdn1.domain.com/iptv/ch2?code=key #F:-1,第二频道rtmp://cdn1.domain.com/iptv/ch3?code=key #F:-1,第三频道rtmp://cdn1.domain.com/iptv/ch4?code=keyIs
所有链接中的静态值是否一致?
是这样的吗:/get.php?code=key
是一整行吗?你能发布3行吗?如果每个链接的键都是相同的,你可以通过php读入并替换字符串。否则,您将需要单独处理每一个。是的,它在所有链接上都是静态的,而您只需执行
str\u replace('code=key','code=123456',$string)
。\f:-1,通道1rtmp://cdn1.domain.com/iptv/ch2?code=key #F:-1,第二频道rtmp://cdn1.domain.com/iptv/ch3?code=key #F:-1,第三频道rtmp://cdn1.domain.com/iptv/ch4?code=key