Jump to content

[SOLVED] Help with a string grabbed using curl


EchoFool

Recommended Posts

I have a script that grabs a file which contains infomation of current song being played.. the previous song played and then the last 20 songs that have been played.

 

Now i successfully grabbed the infomation from the file with the script, and each section is seperated with ||.

 

So i did a str_replace to replace || with a new line... which worked... how ever if i wanted to put:

 

Current Song: ---------------

Previous Song: ---------------

 

Last 20 Songs¬

--------------

--------------

--------------

-------------- 

x20 in total

 

 

How would i go about creating such a crazy format from the string provided?

 

Heres my script:

 

<?php
$curl_handle=curl_init(); 
curl_setopt($curl_handle,CURLOPT_URL,'$Url'); 
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); 
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); 
$buffer = curl_exec($curl_handle); curl_close($curl_handle);
if (empty($buffer)) { 
print "<p>Sorry</p>"; 
} else { 
print_r(str_replace('||','<br>',$buffer)); 
} 

?>

 

Heres an example of what the file holds:

 

Artist - Song Name || Previous Artist - Previous Song Name || x20 previous artist n songs seperated by in same format ||

 

How would i change output to display the data in a format like top of the post shows im guessing im going to use counters to know how many || have gone by but i can't think of how to approach it.

Something like this?:

 

$sep = explode('||', $str);
echo 'Current Song:' . $sep[0] . '<br />';
echo 'Previous Song:' . $sep[1] . '<br />';
echo 'Last 20 Songs:<br />';
for($i = 2;$i < 20;$i++)
{
echo $sep[$i] . '<br />';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.