guytrance Posted August 16, 2012 Share Posted August 16, 2012 Hey Guys. I'm fairly new to PHP so be gentle I have a code on my website that pulls info from a remote xsl file and output it on my header. I need to know how to create CSS rules for that output? <?php /* * SCRIPT CONFIGURATIONS */ $SERVER = 'http://myserver.com:8000'; //URL TO YOUR ICECAST SERVER $STATS_FILE = '/status.xsl'; //PATH TO STATUS.XSL PAGE YOU CAN SEE IN YOUR BROWSER (LEAVE BLANK UNLESS DIFFERENT) ///////////////////// END OF CONFIGURATION --- DO NOT EDIT BELOW THIS LINE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ //create a new curl resource $ch = curl_init(); //set url curl_setopt($ch,CURLOPT_URL,$SERVER.$STATS_FILE); //return as a string curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //$output = our stauts.xsl file $output = curl_exec($ch); //close curl resource to free up system resources curl_close($ch); //build array to store our radio stats for later use $radio_info = array(); $radio_info['server'] = $SERVER; $radio_info['title'] = ''; $radio_info['description'] = ''; $radio_info['content_type'] = ''; $radio_info['mount_start'] = ''; $radio_info['bit_rate'] = ''; $radio_info['listeners'] = ''; $radio_info['most_listeners'] = ''; $radio_info['genre'] = ''; $radio_info['url'] = ''; $radio_info['now_playing'] = array(); $radio_info['now_playing']['artist'] = ''; $radio_info['now_playing']['track'] = ''; //loop through $ouput and sort into our different arrays $temp_array = array(); $search_for = "<td\s[^>]*class=\"streamdata\">(.*)<\/td>"; $search_td = array('<td class="streamdata">','</td>'); if(preg_match_all("/$search_for/siU",$output,$matches)) { foreach($matches[0] as $match) { $to_push = str_replace($search_td,'',$match); $to_push = trim($to_push); array_push($temp_array,$to_push); } } //sort our temp array into our ral array $radio_info['title'] = $temp_array[0]; $radio_info['description'] = $temp_array[1]; $radio_info['content_type'] = $temp_array[2]; $radio_info['mount_start'] = $temp_array[3]; $radio_info['bit_rate'] = $temp_array[4]; $radio_info['listeners'] = $temp_array[5]; $radio_info['most_listeners'] = $temp_array[6]; $radio_info['genre'] = $temp_array[7]; $radio_info['url'] = $temp_array[8]; $x = explode(" - ",$temp_array[9]); $radio_info['now_playing']['artist'] = $x[0]; $radio_info['now_playing']['track'] = $x[1]; echo htmlspecialchars($radio_info['now_playing']['artist'] . ' - ' . $radio_info['now_playing']['track']); echo htmlspecialchars($radio_info['listeners']); ?> Thank you for your help guys Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/ Share on other sites More sharing options...
floridaflatlander Posted August 16, 2012 Share Posted August 16, 2012 Just like you'd create for any other html output. Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369833 Share on other sites More sharing options...
guytrance Posted August 16, 2012 Author Share Posted August 16, 2012 Yeah i figured but..theres no html element or anything... the output come from echo htmlspecialchars($radio_info['now_playing']['artist'] . ' - ' . $radio_info['now_playing']['track']); echo htmlspecialchars($radio_info['listeners']); i cant seem to find the "name" of that output so i can #name it in css..? Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369834 Share on other sites More sharing options...
floridaflatlander Posted August 16, 2012 Share Posted August 16, 2012 Yeah i figured but..theres no html element or anything... what does the echo print/return? Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369835 Share on other sites More sharing options...
guytrance Posted August 16, 2012 Author Share Posted August 16, 2012 It returns song title/info/listeners from IceCast server...single line output. Usually that would be easy to style if it was just a <div>, but its a php code and i dont know what to look for. Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369836 Share on other sites More sharing options...
floridaflatlander Posted August 16, 2012 Share Posted August 16, 2012 Try echo "<p>htmlspecialchars($radio_info['now_playing']['artist'] . ' - ' . $radio_info['now_playing']['track'])</p>"; echo "<p>htmlspecialchars($radio_info['listeners'])</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369842 Share on other sites More sharing options...
guytrance Posted August 16, 2012 Author Share Posted August 16, 2012 Thanx buddy. But i'm getting Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/mystitehere/public_html/mysitehere.com/wp-content/themes/Tersus/header.php on line 247 Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369856 Share on other sites More sharing options...
floridaflatlander Posted August 16, 2012 Share Posted August 16, 2012 Yeah, I don't do I like that so you're going to have to play with it. Try echo "<p>".htmlspecialchars($radio_info['now_playing']['artist'] . ' - ' . $radio_info['now_playing']['track'])."</p>"; echo "<p>".htmlspecialchars($radio_info['listeners'])."</p>"; Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369858 Share on other sites More sharing options...
guytrance Posted August 16, 2012 Author Share Posted August 16, 2012 yup..that worked! now the last thing i need is that this script will refresh every 20 seconds or so..is that possible? And btw..why do i have "&" in every song title the script shows? Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369864 Share on other sites More sharing options...
Christian F. Posted August 16, 2012 Share Posted August 16, 2012 That would probably be htmlspecialchars (), and I recommend reading the PHP manual for more information. As for the update every 20 seconds, you'll probably want to look into jQuery and AJAX for that one. You don't need jQuery, but it makes it a whole lot simpler. Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369888 Share on other sites More sharing options...
guytrance Posted August 16, 2012 Author Share Posted August 16, 2012 Thanks buddy Quote Link to comment https://forums.phpfreaks.com/topic/267165-styling-php-code/#findComment-1369990 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.