Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello, i m in need of a php code that creates a form in which we get to enter a phone number that may be from 5-18 digits and when the submit button in form is pressed it should display the nuber with last four digits starred.
EX- if i enter this number 999922233
output shud come lyk 99992****

please help guys i need to submit this within 5 hrs


<?php
//$strVal = getInput("Please input a phone number : ");
$strVal =$_GET["number"];
if (isset($strVal)) {
    $l = strlen($strVal);
    $strPhone = substr($strVal, $l, ($l - 4)) . "****";
    $NumberPrefix = substr($strVal, 0, ($l - 5));
    echo "Masked Number is : " . $NumberPrefix.$strPhone;
}



?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple PHP Form Demo</title>
</head>
<body>
 
  <form id="number" method="get" action=".">
   <p><label>number: <br />
    <input type="text" name="number" class="textfield" value=" <?php echo htmlentities($NumberPrefix ); ?>" />
    </label></p>
 
    <p><input type="submit" name="submit" class="button" value="Submit" /></p>
  </form>
 
</body>
</html>
Posted
Updated 19-Jun-13 2:25am
v3

1 solution

Hello,

Please have a look at this tutorial[^]. The tutorial will show you how a PHP page can be made to get contact information from the user validate it and re-display.

For a simple non web scenario following snippet should suffice.
PHP
<?php
$strVal = getInput("Please input a phone number : ");
if (isset($strVal)) {
    $l = strlen($strVal);
    $strPhone = substr($strVal, 0, ($l - 4)) . "****";
    echo "Masked Number is : " . $strPhone;
}

function getInput($msg){
  fwrite(STDOUT, "$msg: ");
  $varin = trim(fgets(STDIN));
  return $varin;
}
?>

Regards,
 
Share this answer
 
v2
Comments
nkhldhar 19-Jun-13 2:26am    
also adding to query that i have very less knowledge about php!!
Prasad Khandekar 19-Jun-13 2:35am    
The tutorial should help you. For PHP help refer http://www.php.net/manual/en/language.variables.php.

Regards,
nkhldhar 19-Jun-13 2:41am    
if u could just jot down the code i would be thankful as i m not having much knwledge of php thus cant understand the above stuff
nkhldhar 19-Jun-13 2:50am    
as i need to pass it in 5 hrs i need somebody to help me out with it as soon as possible
nkhldhar 19-Jun-13 2:29am    
see i only have to enter a phone no. that can be from 5-18 digits not full contact details

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900