Home >> Snippet List >> Snippet

Name
Add dashes to credit card numbers
Description
Easily add dashes to credit card numbers
PHP Snippet
<? php
 
FUNCTION AddDash($CC_Num,$CC_Type){ 
IF ($CC_Type="VISA") { 
$NewCC=""; 
FOR ($i=0 ; $i < 4 ; $i++) 
$NewCC=$NewCC.SUBSTR($CC_Num, ($i*4), 4)."-"; 
} 
$NewCC=SUBSTR($NewCC,0,19); 
RETURN ($NewCC); 
} 
 
// Example : 
 
$new_cc_num=AddDash("4580458045804580","VISA"); 
ECHO"$new_cc_num"; 
 
?>