Friday, October 28, 2016

How to find how many parameter / Arguments has been passed and there value

code-
<?php
    function parentFunction($name='name') {
        echo "There are total: ".func_num_args()." Arguments passed.<BR>";
        $args = func_get_args();

echo '<pre>';
print_r($args);
echo '</pre>';

//fetch the value
        for($i = 0; $i < count($args); $i++) {
echo "Passed Value: {$args[$i]}<br />";
        }
      }
    parentFunction($name= 'name','email','phone','location');
?>

login authentcation via browser prompt using PHP




<?php
if (($_SERVER['PHP_AUTH_USER'] != 'a') || ($_SERVER['PHP_AUTH_PW'] != 'a')) {
      header('WWW-Authenticate: Basic Realm="Secret Stash"');
      header('HTTP/1.0 401 Unauthorized');
      print('You must provide the proper credentials!');
      exit;
   }
else{
echo 'login done';
//do stuff here
}
?>

Extract Only numbrs from long string using Regex with PHP (Regular Expressions)

Here is a string -: RT4646R@TWBNSN3234FHFHFH893892389FHDJJD$

Now How will find all red marked numbers in an Array.Here is solution.




<?php
$string = 'RT4646R@TWBNSN3234FHFHFH893892389FHDJJD$';
$special_char = '\[#$%^&*()+=\-\[\]\';,.\/{}|":<>?~\\\\]';
preg_match_all('/\d+/', $string,$output);

echo '<pre>';
print_r($output[0]);
?>






Here is the output

PHP Regular Expressions





Author - 
sudhir k gupta | sudhir gupta | sudhir kumar gupta | eghara
Sudhir K gupta | Lonawala