Last active
January 14, 2018 13:50
-
-
Save TLMcode/2be5a1bc6b5690efb2a50927321b0c88 to your computer and use it in GitHub Desktop.
product or service id en/decode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ## invoice id en/decode | |
function inv_id_code( $id, $act ) | |
{ | |
$str = null; | |
if ( ( $act == 0 || $act == false ) && ( $id != "" ) && preg_match( "/^\w{16}$/i", $id ) == true ) | |
{ | |
foreach( str_split( strrev( $id ), 4 ) as $i => $seg ) | |
{ | |
$str .= "-" . strtoupper( strrev( $seg ) ); | |
} | |
return "INV2" . $str; | |
} | |
else if ( ( $act == 1 || $act == true ) && ( $id != "" ) ) | |
{ | |
foreach( explode( "-", $id ) as $i => $seg ) | |
{ | |
if ( $i > 0 ) | |
{ | |
foreach( str_split( strrev( $seg ) ) as $chr ) | |
{ | |
$str .= rand( 0, 1 ) ? $chr : strtolower( $chr ); | |
} | |
} | |
} | |
return strrev( $str ); | |
} | |
else | |
{ | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment