FREE PHP source code and scripts

PHP function to return a file's suffix

function return_suffix($filename){
    return substr($filename,strrpos($filename,".")+1);
}

PHP function to strip a file's suffix and return the filename without it's suffix (assuming the suffix is 3 characters long)

function strip_suffix($filename){
    return substr($filename,0,-4);
}

PHP function to convert a number of months into years and months

function format_months_to_years_and_months($months){
    $t="";
    $y=floor($months/12);
    $m=$months%12;
    if ($y>1){$t.="$y years ";}else if ($y>0){$t.="$y year ";}
    if ($m>1){$t.="$m months ";}else if ($m>0){$t.="$m month ";}
    return $t;
}

PHP function to remove numbers from a string

function remove_numbers($string) {
     $nums=array("1","2","3","4","5","6","7","8","9","0");
     $string=str_replace($nums,'',$string);
     return $string;
}

If you find any of our free PHP source code useful we would love to hear from you and would be happy to add more if we know someone can benefit from it.

A selection of FREE PHP functions, scripts and source code
Tags: php, php developers, php programming, php web development