How To Get Subversion Revision ID From PHP

By Angsuman Chakraborty, Gaea News Network
Wednesday, January 24, 2007

First of all identify the file(s) for which you want to know the revision number from PHP. Then add a property to the file as follows:
svn propset svn:keywords Revision file_name.php

Now add the following function within php blocks:

/** Returns revision number */
function getSCID() {
    $svnid = '$Rev: 43 $';
    $scid = substr($svnid, 6);
    return intval(substr($scid, 0, strlen($scid) - 2));
}

You can now access the revision number of this file from PHP by calling getSCID(). It returns an integer.

Note: Revision numbers are essential in writing upgrade scripts

Discussion

dave
March 26, 2009: 6:25 am

This will only return the SVN revision number for the php file it operates on. If you update a different file, the revision number for the current file will not increase. See:

https://svnbook.red-bean.com/en/1.4/svn.advanced.props.special.keywords.html


justinas
September 8, 2008: 2:33 am

i think this would be a little bit faster

function getSCID() {
$svnid = '$Rev: 43 $';
$svnid = substr($svnid , 6);
$svnid = substr($svnid , 0, -2);
}

July 9, 2008: 9:37 am

You can use this to check revision number even when you have anonymous access to the subversion repository.

July 8, 2008: 12:24 am

Does this only work when you have actual access to the SVN or could you use this to check the revision number when you have anonymous access?

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :