Help with php .... Some heavy credits for solving it :)

oracle

New Member
Messages
430
Reaction score
0
Points
0
Hey guys I am stuck in a tricky situation:

I have a list of mp3 url's.....However b4 trying to use them into my mp3player, I just want to make sure whether the url's are valid mp3 urls or not (by valid i mean, some might be dead too).

Here are the 4 cases:

Code:
[B]  [I]1) // Resource #2 Ok -> $fixed_url = "http://www.adoptedaustralian.net/glorylibertymix/nanowrimo/05%20Damien%20Rice%20-%20Older%20Chests.mp3";[/I]
  [I]2) // Blank Timed Out -> $fixed_url = "http://bellx1.davejeffery.com/Upload/data/Damien%20Rice-I%20rememer-Damien%5C%27s%20part%20only.mp3";[/I]
  [I]3) // Blank Not found -> $fixed_url = "http://info.showroomseven.com/SHOWROOM_SEVEN/Amber/Eskimo.mp3";[/I]
  [I]4) // Resource id#2 Ok but not mp3 ->$fixed_url = "http://www.flashbacked.net/mp3/04%20Wish%20You%20Were%20Here.mp3";

[/I]I validate them using this code:

[/B]
Code:
$fixed_url = "Choose one of the url from above";
[B]  $urlresponse = @fopen($fixed_url, "r");
  [U]echo[/U] $urlresponse;[/B]

Now the problem is that only 1st url in the list is a valid mp3.

2) and 3) are dead links for which, if u type them directly in the browser u will get timed out or do not exits.

Now the tricky one is the 4th one:
It ends with .mp3 extension, also returns a response to the code, but actually its an html page.
Just type the 4th url in the browser and you would know.

Now I want to filter these cases too. Can someone help me here ??

Points gauranteed to the first correct answer. :)
 

TechAsh

Retired
Messages
5,853
Reaction score
7
Points
38
This is in the wrong forum. It should be in the 'Programming Help' forum.
 

Xemnas

New Member
Messages
812
Reaction score
0
Points
0
*moved from Free Hosting to Programming Help*

oracle, please don't re-post a thread in another forum, as we can easily move threads between forums.
 
Last edited:

bugfinder

Retired
Messages
2,260
Reaction score
0
Points
0
what you need to do with your fopen is if it succeeds, read a few lines, until you find one with the content type on it, if it application/octet-stream or you could check if it returns a line such as "Content-disposition: attachment; filename=xxxxx.mp3"

if it doesnt chances are its not an mp3
 

oracle

New Member
Messages
430
Reaction score
0
Points
0
Lemme try it out, and will get back here.

However i don't think it is best of the solution. Anyways let me see.

thanx
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
i would suggest reading (a part of) the file and then do something like

PHP:
if(preg_match("/<[h|H][t|T][m|M][l|L][.|\n]*>/", $data)) $ishtml = true;
else $ishtml = false;
 
Top