map200uk Posted May 15, 2007 Share Posted May 15, 2007 hi! yet more problems and questions-i am trying to read ogg metadata by opening the file and looking for the tag data, i can manage to echo out the vorbis header, but the commend fields wont echo out, i get random characters-buti can see the data in the file (with a hex editor) whe i try and read the data for album name using fread($file,x) ; and echo it out, its not equal to the album name? anyone have any suggestions! thanks Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/ Share on other sites More sharing options...
phast1 Posted May 15, 2007 Share Posted May 15, 2007 Hello, If you are on Windows, then make sure you added a 'b' parameter to your fopen().. Example: $handle = fopen($filename, "rb"); Hope that helps! Shawn Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-253906 Share on other sites More sharing options...
map200uk Posted May 15, 2007 Author Share Posted May 15, 2007 cheers bud, sadly nope 'rbis)BCV����1L(Ä€ÐU���� ˜6' is the outpu from] i thought perhaps an encoding issue?! <?php $fp=fopen("07-maroon_5-cant_stop.ogg","rb"); fseek($fp,150); $test=fread($fp,30); echo $test; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-253912 Share on other sites More sharing options...
phast1 Posted May 15, 2007 Share Posted May 15, 2007 Hmm, I don't think it's an encoding issue, it looks more like a file pointer issue because your output seems to be coming from the 104 line of your hex output instead of the 82 line that you are trying to read.. What happens if you don't do a fseek? Does it seem to start from the beginning of the file? If so, then you might just need to adjust the fseek.. I'm not too familiar with reading binary files, so maybe someone else will have some suggestions if that doesn't help.. Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-253948 Share on other sites More sharing options...
map200uk Posted May 15, 2007 Author Share Posted May 15, 2007 Makes no difference mate:( Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-253962 Share on other sites More sharing options...
map200uk Posted May 15, 2007 Author Share Posted May 15, 2007 thing is if i do echo file_get_contents(file.ogg) i see the data i am trying to extract?!which must mean it can be echoed out? OggS���������Ý¢����!)‚evorbis����D¬������q�����¸OggS����������Ý¢���® ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿvorbis���Xiph.Org libVorbis I 20020717������Album=avvvv���Artist=avril���Comment=aaa���Genre=Alt. Rock���Title=girlfriend ���Tracknumber=2 ���Date=2808vorbis)BCV����1L(Ä€ÐU���� Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-253975 Share on other sites More sharing options...
phast1 Posted May 15, 2007 Share Posted May 15, 2007 Very strange that file_get_contents() shows the correct data but fread() doesn't.. I would just use whatever works, maybe something like this: $data = file_get_contents(file.ogg); $album = substr($data, 150, 30); echo $album; That should accomplish the same thing that you were trying to do with fread()? Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-254001 Share on other sites More sharing options...
map200uk Posted May 16, 2007 Author Share Posted May 16, 2007 yep made no sense to me mate phast1, the thing is it seems that with the file it varies i.e say album was a max of 32 bytes it could only be 2 and is seperated by ascii code 11 so i.e. Name 0 0 11 Album obviously the 0 are NULL and the 11 is well i think | ? woukld the best way to do this to be to read say 100 bytes of the file in, then look for this seperator and each time split it based on this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-254128 Share on other sites More sharing options...
phast1 Posted May 16, 2007 Share Posted May 16, 2007 Yeah, if the length varies, which it definitely would being an album name, you should read in as many characters as you think the max could be, and then parse out based on a separater.. It sounds like you found the separater, so that should work out good. Best of luck! Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-254140 Share on other sites More sharing options...
map200uk Posted May 16, 2007 Author Share Posted May 16, 2007 i think i have but not sure what is ascii ii i thought its a tab, php echoes it as [] chr(11) but when i look at the file contents the byte where its ascii 11 = | ? perhaps tab is represented as | inside a file? thanks Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-254545 Share on other sites More sharing options...
phast1 Posted May 16, 2007 Share Posted May 16, 2007 It looks like ASCII 11 is a vertical tab according to http://www.asciitable.com/ .. And yeah, your editor is most likely using the pipe symbol (|) just to represent the vertical tab.. I wouldn't worry too much about the character being represented though, just do the test for ASCII char 11, such as: if ($var == chr(11)) Quote Link to comment https://forums.phpfreaks.com/topic/51560-reading-file-data/#findComment-254650 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.