WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : ID3v2 tag extractor in PHP
Categories : PHP, Tag Extractors Update Picture
Anders Bruun
Date : Mar 01st 2001
Grade : 2 of 5 (graded 3 times)
Viewed : 8442
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Anders Bruun
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?
/*
This file was written by Anders Bruun Olsen (anders@gerf.dk)
It is all released under the GNU GPL license and therefore free
for everybody to use.
I hope that someone will find it useful and perhaps clean it up
and make it a bit smoother..

For those in doubt, it is used by giving a filename (preferebly
with a full path) of an MP3 file containing an ID3v2 tag to
extract_id3v2().
An array is then returned containing all the frames in the tag.
*/

function rem_synchsafe ($tal)
{
        $tal = hexdec(bin2hex($tal));
        $tal1 = floor($tal/256) * 128 + ($tal%256);
        $tal2 = floor($tal1/32768) * 16384 + ($tal1%32768);
        $sluttal = floor($tal2/4194304) * 2097152 + ($tal2%4194304);
        return $sluttal;
};

function get_flags ($fp)
{
        // This function reads the flag bit and puts out something useful...
        $flags = hexdec(bin2hex(fgetc($fp)));
        if (($flags - 128) >= 0) {
                // flag a is set (Unsynchronisation)
                $flags = $flags - 128;
                $flaglist .= "a,";
        }
        if (($flags - 64) >= 0) {
                // flag b is set (Extended Header)
                $flags = $flags - 64;
                $flaglist .= "b,";
        }
        if (($flags - 32) >= 0) {
                // flag c is set (Experimental indicator)
                $flags = $flags - 32;
                $flaglist .= "c,";
        }
        if (($flags - 16) >= 0) {
                // flag d is set (Footer present)
                $flags = $flags - 16;
                $flaglist .= "d,";
        }
if (($flags - 8) >= 0) {
// flag e is set (Unused in v2.4.0)
$flags = $flags - 8;
$flaglist .= "e,";
}
if (($flags - 4) >= 0) {
// flag f is set (Unused in v2.4.0)
$flags = $flags - 4;
$flaglist .= "f,";
}
if (($flags - 2) >= 0) {
// flag g is set (Unused in v2.4.0)
$flags = $flags - 2;
$flaglist .= "g,";
}
if (($flags - 1) >= 0) {
// flag h is set (Unused in v2.4.0)
$flags = $flags - 1;
$flaglist .= "h,";
}
        if (strlen($flaglist) > 0)
        {
                $flaglist = substr($flaglist,0,strlen($flaglist)-1);
        }
        return $flaglist;
};

function get_id3pos ($filename)
{
        // This function will return the position of the ID3v2 tag if found
        $fp = fopen($filename,"r");
        while(!feof($fp)){
                $char = fgetc($fp);
                if($char == "I") {
                        $char = fgetc($fp);
                        if ($char == "D") {
                                $char = fgetc($fp);
                                if ($char == "3") {
                                        $id3pos = ftell($fp);
                                }
                        }
                }
        }
        fclose($fp);
        if (!$id3pos) {
                return false;
        } else {
                return $id3pos;
        }
};

function goto_id3pos ($filename,$id3pos)
{
        // This function will open the file, go to the ID3v2 tag position and return the filepointer
        $fp = fopen($filename,"r");
        if (fseek($fp,$id3pos) != 0) {
                die ("Could not go to ID3 tag\n");
        }
        return $fp;
};

function get_id3_version ($fp)
{
        // This function gets the ID3v2 version from the file open at the filepointer and returns it
        $ver1 = hexdec(bin2hex(fgetc($fp)));
        $ver2 = hexdec(bin2hex(fgetc($fp)));
        $version = "ID3v2." . $ver1 . "." . $ver2;
        return $version;
};

function get_tagsize ($fp)
{
        // This function gets the tagsize converts it from a synchsafe int to a normal int and returns it
        for ($i = 0; $i < 4; $i++) {
                $tagsize .= fgetc($fp);
        }
        $tagsize = rem_synchsafe($tagsize);
        return $tagsize;
};

function extract_id3v2($filename)
{
        // Find the position of the ID3v2 tag
        
        if (!$id3pos = get_id3pos($filename)) {
                die("No ID3v2 tag found in $filename\n");
        };
        
        // go to id3v2 tag in file
        
        $fp = goto_id3pos($filename,$id3pos);
        
        // Get the version
        
        $id3ver = get_id3_version($fp);
        
        $id3flags = get_flags($fp);
        
        $tagsize = get_tagsize($fp);
        $tagsize_left = $tagsize;
        while ($tagsize_left > 1) {
                unset($frameID);
                unset($framesize);
                unset($frame);
                for ($i = 0; $i < 4; $i++) {
                        $frameID .= fgetc($fp);
                }
                for ($i = 0; $i < 4; $i++) {
                        $framesize .= fgetc($fp);
                }
                $framesize = rem_synchsafe($framesize);
                if ($framesize >= 1)
                {
                        $tagsize_left = $tagsize_left - ($framesize + 10);
                        $flag1 = get_flags($fp);
                        $flag2 = get_flags($fp);
                        $encoding = hexdec(bin2hex(fgetc($fp)));
                        if ($encoding <= 3) {
                                // This is the encoding bit
                                for ($i = 0; $i < ($framesize - 1); $i++) {
                                        $frame .= fgetc($fp);
                                }
                        } else {
                                // This was not an encoding bit, it is part of the frame content
                                $frame = $encoding;
                                for ($i = 0; $i < $framesize; $i++) {
                                        $frame .= fgetc($fp);
                                }
                        }
                }
                else
                {
                        $frameID = "Padding";
                        $tagsize_left = 0;
                }
                if ($frameID == "SYLT" OR $frameID == "USLT" OR $frameID == "USER" OR $frameID == "COMM")
                {
                        $frame = substr($frame,3,strlen($frame));
                }
                $framearray["$frameID"] = $frame;
        };
        fclose($fp);
        return $framearray;
}
?>



PHP based HTML rabbing Tools
Categories : PHP, HTML and PHP, Tag Extractors, Regexps, Beginner Guides
MP3 Tag reader module.
Categories : PHP, Tag Extractors
Parse a HTML-document for a certain tag and display its content and attributes.
Categories : HTML and PHP, PHP, Tag Extractors
Parsing html tags with php. Get an array from this function
Categories : PHP, HTML and PHP, Arrays, Tag Extractors
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
time() function with microseconds
Categories : Date Time, PHP
My Box - PHP Class that calculates the volumetric weight of a package.
Categories : PHP, Object Oriented, PHP Classes, Beginner Guides, Payment Gateways
Database Connectivity with MS Access - The Easy way to work with PHP and MS Access
Categories : PHP, ADO, MS Access, Databases
credit card security code
Categories : PHP, Credit Cards, PHP Classes, Credit Cards
Inline Scope Control - The inline class provides methods for creating and destroying local variable scopes. Simply put, local scopes are spaces where some or all of the global variables are temporarily hidden.
Categories : PHP, PHP Classes, Variables
TableMaint: class to help in the updating of data stored in database tables
Categories : PHP, PHP Classes, Databases
Compare two texts and display a block of text with the differences between them.
Categories : PHP, PHP Classes, Filesystem, Strings, Arrays
hw_Changeobject -- changes object
Categories : PHP, PHP Functions, Hyperwave
Logs hits to any page which includes it. Automatically utilises page access information left behind by PHP/FI2.0.
Categories : Databases, PHP, mSQL, Databases
Linkers Class
Categories : PHP Classes, PHP
 Anders Olsen wrote :538
If you run into trouble with PHP timeouts it is because of the loop that locates the ID3v2 tag position. As most ID3v2 tags are found in the beginning of files I have modified the code to skip that loop and just read the tag from the start.
This means that files where the tag is not located in the beginning is not supported.
The newest version of this code can be found at:
http://www.elffan.com/id3v2