Skip to content

Instantly share code, notes, and snippets.

@TLMcode
Last active January 14, 2018 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TLMcode/2be5a1bc6b5690efb2a50927321b0c88 to your computer and use it in GitHub Desktop.
Save TLMcode/2be5a1bc6b5690efb2a50927321b0c88 to your computer and use it in GitHub Desktop.
product or service id en/decode
// ## 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