Login | Register

Info | Home

BioPHP - Return "halves" of palindromics sequences

Original code submitted by joseba
Code bellow is covered by GNU GPL v2 license.

Description

Last change: 2010/10/18 17:04 | Edit description | Recent Changes | Original description
Returns one of the two palindromic \"halves\" of a palindromic string. 

Code

Last change: 2010/10/18 17:04 | Edit Code | Recent Changes | Download | Original code
function halfstr($string, $no)
        {
        // for now, this holds for mirror repeats.
        if (is_odd(strlen($string)))
                {
                $comp_len = (int) (strlen($string)/2);
                if ($no == 0) return substr($string, 0, $comp_len);
                else return substr($string, $comp_len + 1);
                }
        else
                {
                $comp_len = strlen($string)/2;
                if ($no == 0) return substr($string, 0, $comp_len);
                else return substr($string, $comp_len);
                }
        }