Jump to content

Here Is One For You


jaymc

Recommended Posts

Right, I'll drop you straight in it. I have about 2000 .txt files that look like the below code

[code]<?
$music = $_GET['send'];

if (strpos($music, "2diealbum1"))  {
$song = "2diealbum/songs/2diealbum/2diealbum1.wma";
$songdisplay = "2die4 - Paranoid Entity";
}

else if (strpos($music, "2diealbum2"))  {
$song = "2diealbum/songs/2diealbum/2diealbum2.wma";
$songdisplay = "2die4 - Hell On Earth";
}

else if (strpos($music, "2diealbum3"))  {
$song = "2diealbum/songs/2diealbum/2diealbum3.wma";
$songdisplay = "2die4 - Im Ok";
}

else if (strpos($music, "2diealbum4"))  {
$song = "2diealbum/songs/2diealbum/2diealbum4.wma";
$songdisplay = "2die4 - Reminissin";
}

else if (strpos($music, "2diealbum5"))  {
$song = "2diealbum/songs/2diealbum/2diealbum5.wma";
$songdisplay = "2die4 - Listen To Your Heart";
}

else if (strpos($music, "2diealbum6"))  {
$song = "2diealbum/songs/2diealbum/2diealbum6.wma";
$songdisplay = "2die4 - Take It Slow";
}

else if (strpos($music, "2diealbum7"))  {
$song = "2diealbum/songs/2diealbum/2diealbum7.wma";
$songdisplay = "2die4 - Do Ya Like That";
}

else if (strpos($music, "2diealbum8"))  {
$song = "2diealbum/songs/2diealbum/2diealbum8.wma";
$songdisplay = "2die4 - Just The Begining";
}

else if (strpos($music, "2diealbum9"))  {
$song = "2diealbum/songs/2diealbum/2diealbum9.wma";
$songdisplay = "2die4 - Put Em Down";
}

else if (strpos($music, "2diealbuma"))  {
$song = "2diealbum/songs/2diealbum/2diealbuma.wma";
$songdisplay = "2die4 - Earths Condition";
}

else if (strpos($music, "2diealbumb"))  {
$song = "2diealbum/songs/2diealbum/2diealbumb.wma";
$songdisplay = "2die4 - By My Side";
}

else if (strpos($music, "2diealbumc"))  {
$song = "2diealbum/songs/2diealbum/2diealbumc.wma";
$songdisplay = "2die4 - I Needed You";
}

else if (strpos($music, "2diealbumd"))  {
$song = "2diealbum/songs/2diealbum/2diealbumd.wma";
$songdisplay = "2die4 - Its Ok To Cry";
}

else if (strpos($music, "2diealbume"))  {
$song = "2diealbum/songs/2diealbum/2diealbume.wma";
$songdisplay = "2die4 - Easy Lover";
}

else if (strpos($music, "2diealbumf"))  {
$song = "2diealbum/songs/2diealbum/2diealbumf.wma";
$songdisplay = "2die4 - Throw It Up";
}

else if (strpos($music, "2diealbumg"))  {
$song = "2diealbum/songs/2diealbum/2diealbumg.wma";
$songdisplay = "2die4 - Me In General";
}

else if (strpos($music, "2diealbumh"))  {
$song = "2diealbum/songs/2diealbum/2diealbumh.wma";
$songdisplay = "2die4 - Catch A Breath";
}

else if (strpos($music, "2diealbumi"))  {
$song = "2diealbum/songs/2diealbum/2diealbumi.wma";
$songdisplay = "2die4 - It Aint Easy";
}

else  if (strpos($music, "2diealbumplay")) {
$song = "2diealbum/songs/2diealbum/2diealbumplay.wax";
$songdisplay = "2die4 - Complete Album";


?>[/code]


I am going to create a script that will loop and read in the entire contents of each .txt file

Then, I need to dig out the following information from each else if. Ive put the information I need in BOLD

else if (strpos($music, "[b]2diealbumi[/b]"))  {
$song = "[b]2diealbum/songs/2diealbum/2diealbumi.wma[/b]";
$songdisplay = "[b]2die4 - It Aint Easy[/b]";
}

What is the best way to do this. Its a bit messy but how would you do it?

P.S, its not the loop on stuck with, its the handling of the data
Link to comment
https://forums.phpfreaks.com/topic/21314-here-is-one-for-you/
Share on other sites

if (strpos($music, "2diealbum1"))  {
$song = "2diealbum/songs/2diealbum/2diealbum1.wma";
$songdisplay = "2die4 - Paranoid Entity";
}

If it's garaunteed that the data you need is [b]always[/b] enclosed in double quotes and that it [b]always[/b] appears in that order, you can follow this algorithm:

1) Open file
2) Using a regular expression, fill an array with all data enclosed in double quotes only
3) With the array
  a) Starting at index 0, every third element comes from the line containing [b]strpos[/b]
  b) Starting at index 1, every third element comes from the line containing [b]$song =[/b]
  c) Starting at index 2, every third element comes from the line containing [b]$songdisplay =[/b]

All it takes is for one body of the if / else if construct to assign variables out of order to ruin that approach though.
Link to comment
https://forums.phpfreaks.com/topic/21314-here-is-one-for-you/#findComment-94889
Share on other sites

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.