我有一个包含 soundcloud 轨道 URL 列表的文本文件。我还有一个 php 文件,它随机选择其中一个 URL,并允许我在不同的 php 文件中接收它。现在由于某种原因,当我将 $url 设置为随机选择的 URL 并在下一行调用它时。我得到的只是 URL 的文本版本,而不是 iframe soundcloud 嵌入代码。
<?php
//Get the SoundCloud URL
$url = $_GET['type'] = 0; include 'http://example.com/randomselector.php';
//Get the JSON data of song details with embed code from SoundCloud oEmbed
$getValues=file_get_contents(
'http://soundcloud.com/oembed?format=js&url='.$url.'&iframe=true');
//Clean the Json to decode
$decodeiFrame=substr($getValues, 1, -2);
//json decode to convert it as an array
$jsonObj = json_decode($decodeiFrame);
//Change the height of the embed player if you want else uncomment below line
echo $jsonObj->html;
?>
我试图在第二行手动插入一个 URL 并且可以正常工作。这意味着我得到了 iframe 嵌入代码。
这是随机选择器.php
<?php
/* File, where the random text/quotes are stored one per line */
$settings['text_from_file'] = 'http://example.com/list.txt';
/*
How to display the text?
0 = raw mode: print the text as it is, when using RanTex as an include
1 = Javascript mode: when using Javascript to display the quote
*/
$settings['display_type'] = 0;
/* Allow on-the-fly settings override? 0 = NO, 1 = YES */
$settings['allow_otf'] = 1;
/*******************************************************************************
*******************************************************************************/
/* Override type? */
if ($settings['allow_otf'] && isset($_GET['type']))
{
$type = intval($_GET['type']);
}
else
{
$type = $settings['display_type'];
}
/* Get a list of all text options */
if ($settings['text_from_file'])
{
$settings['quotes'] = file($settings['text_from_file']);
}
/* If we have any text choose a random one, otherwise show 'No text to choose from' */
if (count($settings['quotes']))
{
$txt = $settings['quotes'][array_rand($settings['quotes'])];
}
else
{
$txr = 'No text to choose from';
}
/* Output the image according to the selected type */
if ($type)
{
/* New lines will break Javascript, remove any and replace them with <br /> */
$txt = nl2br(trim($txt));
$txt = str_replace(array("\n","\r"),'',$txt);
echo 'document.write(\''.addslashes($txt).'\')';
}
else
{
echo $txt;
}
?>
这是列表.txt
Link1
Link2
Link3