Apache2Triad Help, Support and Development Forum Index Search Profile Log in to check your private messages Log in Register Memberlist Attachments Statistics Crew/Ranks Archive
 [PHP] Problems with unknown garbage in string.
Google
Post new topic Reply to topic
Author Message
Joshua Meadows (DemoRic)
support
support


Joined: 29 Dec 2004
Posts: 783
Location: S.E. Kansas

PostPosted: Fri Dec 29, 2006 3:39 pm Reply with quoteBack to top

Okay I'm using a function to retrieve ID3 info from MP3 files, and I use it to build xspf playlists. However I have some mp3's that place garbage in the string data. I'm guessing it's a break of some variety. I can't copy and paste the data as it will automatically do the break function.

While php can display this char as an unknown character (a box) it messes up the xspf playlist.

I've tried to remove it via another function.
Code:
function utrim($source){
   $temp = ltrim($source);
   $temp = rtrim($temp);
   $temp = trim($temp);
   $temp = trim($temp, "\x7f..\xff\x0..\x1f");
   $temp = trim($temp, "\n\t\r\h\v\0 ");
   $temp = str_replace (" ","",$temp);

   // Ascii Values http://www.asciitable.com/
   $temp = str_replace (chr(27),"",$temp);   
   $temp = str_replace (chr(3),"",$temp);   
   $temp = str_replace (chr(4),"",$temp);   
   $temp = str_replace (chr(23),"",$temp);   
   $temp = str_replace (chr(254),"",$temp);   

   $temp = htmlentities($temp);
   $temp = str_replace (" "," ",$temp);
   $temp = str_replace ("ΒΆ"," ",$temp);
   $temp = html_entity_decode($temp);
   return $temp;
 }


I just can't seem to identify what the character is, or be able to remove it.
View user's profileSend private messageYahoo MessengerICQ Number
dale
 
 


Joined: 11 Jun 2006
Posts: 51
Location: las vegas, nv

PostPosted: Sun Dec 31, 2006 7:59 am Reply with quoteBack to top

I used a hex editor to see what the tags on the different mp3's that I had and it appears to me that different source programs put different stuff in their headers. If you only had a few odd ones I would suggest looking for the non printable symbols and put them in your list, ie hex(00) is a favorite.

Another thought is to have two loops where the first loop checks for the value of the substring from 0 to 31 and the other loop check for 123 to 255 to replace the non printable characters with the null value.

I used the values from http://www.asciitable.com/. You might also consider keeping the lines for the special characters in the range of printable characters like " ' and ; if they give you problems also.

Hope this helps.
View user's profileSend private message
Joshua Meadows (DemoRic)
support
support


Joined: 29 Dec 2004
Posts: 783
Location: S.E. Kansas

PostPosted: Sun Dec 31, 2006 11:54 pm Reply with quoteBack to top

Dale, my hats off to your solution. I kept guessing at the chr, I didn't even think to just completely remove the whole range of non printable symbols.

Works like a charm. Very Happy
View user's profileSend private messageYahoo MessengerICQ Number
Display posts from previous:      
Post new topic Reply to topic


 Jump to:   



View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Powered by phpBB © 2001, 2002 phpBB Group :: FI Theme
All times are GMT