EchoFool Posted June 16, 2009 Share Posted June 16, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/162316-solved-help-with-a-string-grabbed-using-curl/ Share on other sites More sharing options...
Alex Posted June 16, 2009 Share Posted June 16, 2009 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 />'; } Quote Link to comment https://forums.phpfreaks.com/topic/162316-solved-help-with-a-string-grabbed-using-curl/#findComment-856731 Share on other sites More sharing options...
EchoFool Posted June 16, 2009 Author Share Posted June 16, 2009 Oh didn't know it used an array! Sweet it was easier than i thought ! Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/162316-solved-help-with-a-string-grabbed-using-curl/#findComment-856770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.