ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to take data off of the shoutcast page I use on my Linux box, and create a status page off of it, but I am not having luck on my own.
I want to take this line for example:
[HTML]<tr><td width=100 nowrap><font class=default>Current Song: </font></td><td><font class=default><b>15 Ahhh</b></td></tr>[/HTML]
And pull the data between
[HTML]<tr><td width=100 nowrap><font class=default>Current Song: </font></td><td><font class=default><b>[/HTML]
and
[HTML]</b></td></tr>[/HTML]
I'm hoping if I could get some help on how to get a simple page that can pull this data, I can then manage to figure the rest out on my own. Any help would be appreciated.
I'm having difficulty getting the preg match to work correctly. I'm trying to get everything after "Current Song: " and before "Written by Stephen 'Tag Loomis,". Could someone give me some help with Regular Expressions in PHP?
mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); echo "($string)"; $query="SELECT * FROM `musicmetadata` WHERE `filename` LIKE '%$string%'"; $result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
echo "<h1><b><center>Search Results</center></b></h1>"; echo "<h3><b>Found $num Matching Songs To Your Search.</b></h3>"; echo "<h3><b>Click On The Song Title To Request The Song To Be Played.</b></h3><br>"; $i=0; while ($i < $num) {
echo "<b>Artist: <P2>$artist</P2> Title: <P2><a target='Log' href='request.php?request_id=$intid'>$title</a></P2><br>Album: <P2>$album</P2></b> Year: <P2>$year</P2><br>Song # <P2>$intid</P2> Genre: <P2>$genre</P2><br> Length: <P2>$length ms or $length2:$length3.</P2><br>Filename: $filename<br><hr>";
$i++; }
return $string; }
#$string = "Current Song: 10 Walk On The Ocean - Toad the Wet Sprocket Written By blah blah"; $string = $cont; $str1 = "Current Song: "; $str2 = "Written";
My only issue that I am having now is that I can't seem to get rid of a space at the end of the string I pull out of the data. I'm using the data to search though mySQL and pull down data. I've tried messing with the code, but can't get rid of that space on the end. Any idea on how to do that?
The trim() function can be used to strip whitespace from both ends of a string, there is also ltrim() and rtrim() to strip it from the start or end respectively.
I've got the minutes and seconds perfect, unless a song comes up that is, for example, 1:03. It shows up as 1:3 with what I have. All I need is to add a 0 to the front of the variable when it happens. You can see my pathetic attempt at doing that. Any clues for me?
Thanks graemef! That worked perfectly. I think that takes care of this part of my project. If I have any other questions, I'll open a new thread. Thanks again!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.