Apache2Triad Help, Support and Development Forum Index Apache2Triad Help, Support and Development
The apache2triad help , support and development forums
 

[PHP] Problems with unknown garbage in string.
Click here to go to the original topic

 
       Apache2Triad Help, Support and Development Forum Index -> Programming
View previous topic :: View next topic  
Author Message
Joshua Meadows (DemoRic)



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

Posted: Fri Dec 29, 2006 3:39 pm    Post subject: [PHP] Problems with unknown garbage in string.  

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.
Back to top  
dale



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

Posted: Sun Dec 31, 2006 7:59 am    Post subject:  

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.
Back to top  
Joshua Meadows (DemoRic)



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

Posted: Sun Dec 31, 2006 11:54 pm    Post subject:  

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. :D
Back to top  
 
       Apache2Triad Help, Support and Development Forum Index -> Programming
Page 1 of 1


Powered by phpBB Search Engine Indexer
Powered by phpBB 2.0.13 © 2001, 2002 phpBB Group