src/Biblys/Isbn/Isbn.php
private function removeCountryCode($code)
    {

        // Get the seven first digits
        $first7 = substr($code, 0, 7);

        // Select the right set of rules according to the product code
        foreach ($this->getRanges()->getPrefixes() as $p) {
            if ($p['Prefix'] == $this->getProduct()) {
                $rules = $p['Rules']['Rule'];
                break;
            }
        }

        // If product code was not found, cannot proceed
        if (empty($rules)) {
            return null;
        }

        // Select the right rule
        foreach ($rules as $r) {
            $ra = explode('-', $r['Range']);
            if ($first7 >= $ra[0] && $first7 <= $ra[1]) {
                $length = $r['Length'];
                break;
            }
        }

        // Country code is invalid
        if ($length === "0") {
            $this->setValid(false);
            $this->addError(self::ERROR_INVALID_COUNTRY_CODE);
            return $code;
        }

        $this->setCountry(substr($code, 0, $length));
        $code = substr($code, $length);

        return $code;
    }
private function removeCountryCode($code)
    {

        // Get the seven first digits
        $first7 = substr($code, 0, 7);

        // Select the right set of rules according to the product code
        foreach ($this->getRanges()->getPrefixes() as $p) {
            if ($p['Prefix'] == $this->getProduct()) {
                $rules = $p['Rules']['Rule'];
                break;
            }
        }

        // If product code was not found, cannot proceed
        if (empty($rules)) {
            return null;
        }

        // Select the right rule
        foreach ($rules as $r) {
            $ra = explode('-', $r['Range']);
            if ($first7 >= $ra[0] && $first7 <= $ra[1]) {
                $length = $r['Length'];
                break;
            }
        }

        // Country code is invalid
        if ($length === "0") {
            $this->setValid(false);
            $this->addError(self::ERROR_INVALID_COUNTRY_CODE);
            return $code;
        }

        $this->setCountry(substr($code, 0, $length));
        $code = substr($code, $length);

        return $code;
    }
private function removeCountryCode ( $ code ) { // Get the seven first digits $ first7 = substr ( $ code , 0 , 7 ) ; // Select the right set of rules according to the product code foreach ( $ this -> getRanges ( ) -> getPrefixes ( ) as $ p ) { if ( $ p [ 'Prefix' ] == $ this -> getProduct ( ) ) { $ rules = $ p [ 'Rules' ] [ 'Rule' ] ; break ; } } // If product code was not found, cannot proceed if ( empty ( $ rules ) ) { return null ; } // Select the right rule foreach ( $ rules as $ r ) { $ ra = explode ( '-' , $ r [ 'Range' ] ) ; if ( $ first7 >= $ ra [ 0 ] && $ first7 <= $ ra [ 1 ] ) { $ length = $ r [ 'Length' ] ; break ; } } // Country code is invalid if ( $ length === "0" ) { $ this -> setValid ( false ) ; $ this -> addError ( self :: ERROR_INVALID_COUNTRY_CODE ) ; return $ code ; } $ this -> setCountry ( substr ( $ code , 0 , $ length ) ) ; $ code = substr ( $ code , $ length ) ; return $ code ; }
Remove and save Country Code
Remove and save Country Code