Author Topic: Here Is One For You  (Read 617 times)

0 Members and 1 Guest are viewing this topic.

Offline jaymcTopic starter

  • Addict
  • Posts: 1,528
  • Gender: Male
    • View Profile
    • SEO Agency
Here Is One For You
« on: September 19, 2006, 03:21:05 PM »
Right, I'll drop you straight in it. I have about 2000 .txt files that look like the below code

Code: [Select]
<?
$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";


?>


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, "2diealbumi"))  {
$song = "2diealbum/songs/2diealbum/2diealbumi.wma";
$songdisplay = "2die4 - It Aint Easy";
}

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
I would love to change the world, but they won't give me the source code

SEO Agency

Offline businessman332211

  • Fanatic
  • Posts: 3,883
  • Gender: Male
    • View Profile
    • Information Technologist
Re: Here Is One For You
« Reply #1 on: September 19, 2006, 03:22:59 PM »
file_get_contents()
or fopen or something similar
then use regular expressions for whatever you need,.
Business Website: www.infotechnologist.biz
Writing Site: www.realmofwriting.com
Personal Site: www.ninjakreborn.com
http://www.onlinewasteland.com/ - Random tools for your random needs
http://secure.hostgator.com/~affiliat/cgi-bin/affiliates/clickthru.cgi?id=ninjakreborn - (Use code ninjakreborn for 10 dollars off).

Offline jaymcTopic starter

  • Addict
  • Posts: 1,528
  • Gender: Male
    • View Profile
    • SEO Agency
Re: Here Is One For You
« Reply #2 on: September 19, 2006, 03:25:50 PM »
Can you give me an example of how to use regular expressions with what I need
I would love to change the world, but they won't give me the source code

SEO Agency

Offline Orio

  • Staff Alumni
  • Addict
  • *
  • Posts: 2,496
  • Gender: Male
    • View Profile
    • OriosRiddle
Re: Here Is One For You
« Reply #3 on: September 19, 2006, 03:28:04 PM »
I would recommened you to use strstr() and substr() since the lengthes of the code parts are the same all the time. That will replace regular expressions.

Orio.
Think you're smarty?

(Gone until 20 to November)

Offline jaymcTopic starter

  • Addict
  • Posts: 1,528
  • Gender: Male
    • View Profile
    • SEO Agency
Re: Here Is One For You
« Reply #4 on: September 19, 2006, 03:41:55 PM »
So the only real feasable approach is probably to explode by lines and use strstr()
I would love to change the world, but they won't give me the source code

SEO Agency

Offline roopurt18

  • Guru
  • Fanatic
  • *
  • Posts: 3,658
  • Gender: Male
  • le sigh
    • View Profile
    • rbredlau
Re: Here Is One For You
« Reply #5 on: September 19, 2006, 03:52:16 PM »
if (strpos($music, "2diealbum1"))  {
$song = "2diealbum/songs/2diealbum/2diealbum1.wma";
$songdisplay = "2die4 - Paranoid Entity";
}

If it's garaunteed that the data you need is always enclosed in double quotes and that it always 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 strpos
  b) Starting at index 1, every third element comes from the line containing $song =
  c) Starting at index 2, every third element comes from the line containing $songdisplay =

All it takes is for one body of the if / else if construct to assign variables out of order to ruin that approach though.