当前,我有一个运行良好的脚本!而且我必须根据情况使用GET参数,不幸的是,我的旧智能电视仍然无法识别&符号
例如:
http://localhost/share.php?code=161494581&nativo=sim&url=http://cdn100.ntncc.stream/prop/httpdelivery/14004787mega.mp4&mediaType=fixit&mediaName=Mega&mediaClose=2000&idfy=1
在我的smartv中,链接在第一个&符号处停止。因此,我将使用其他符号,例如 |
http://localhost/share.php|code=161494581|nativo=sim|url=http://cdn100.ntncc.stream/prop/httpdelivery/14004787mega.mp4|mediaType=fixit|mediaName=Mega|mediaClose=2000|idfy=1
并且我正在尝试创建一个脚本以拆分全部| | | | |。符号,然后使用split =符号将名称归因于相应的值。
这是我的PHP脚本:
$string = "https://<private-urk>/player/share.php|code=161494581|nativo=sim|url=http://cdn100.ntncc.stream/prop/httpdelivery/14004787mega.mp4|mediaName=Megatubarão|mediaClose=2000|idfy= 1";
$split1 = explode('|', $string);
$arr = [];
foreach ($split1 as $value) {
$split2 = explode('=', $value);
$_GET[$split2[0]] = $split2[1];
echo $_GET[$split2[0]];
}
该脚本无法正常工作,它显示了错误的值,我不知道该怎么做。你能帮我吗?
答案 0 :(得分:0)
使用此:
<?php
$string = "https://topflix.tv/player/share.php|code=161494581|nativo=sim|url=http://cdn1.ntcdn.stream/prop/httpdelivery/filmes/p1/14004787megatubarao-2018.mp4|mediaType=filme|mediaName=Megatubarão|mediaYear=2018|idfy=1";
$split1 = explode('|', $string);
foreach ($split1 as $value) {
$split2 = explode('=', $value);
if(isset($split2[1])){//check value
$_GET[$split2[0]] = $split2[1];
echo $_GET[$split2[0]];}
}
答案 1 :(得分:0)
您可以再次将|
替换为&
,去掉URL,然后使用parse_str
:
$string = "https://topflix.tv/player/share.php|code=161494581|nativo=sim|url=http://cdn1.ntcdn.stream/prop/httpdelivery/filmes/p1/14004787megatubarao-2018.mp4|mediaType=filme|mediaName=Megatubarão|mediaYear=2018|idfy= 1";
$string = substr($string, strpos($string, '|'));
parse_str(str_replace('|', '&', $string), $_GET);
print_r($_GET);
输出:
Array (
[code] => 161494581
[nativo] => sim
[url] => http://cdn1.ntcdn.stream/prop/httpdelivery/filmes/p1/14004787megatubarao-2018.mp4
[mediaType] => filme
[mediaName] => Megatubarão
[mediaYear] => 2018
[idfy] => 1
)