Monday, December 9, 2013

Get the current Page Url

<?PHP


///Get the current Page Url



function currentPageUrl() {
 $pageURL = 'http';
 if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}

 $pageURL .= "://";

 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}


echo  currentPageUrl();

?>

Check the given striong have any HTML Tags

<?PHP

  
    /*
     * Check if a string is html
     *
     * @param  string $string string to check
     * @return bool
     */
     function is_html($string)
    {
      
        if ( strlen(strip_tags($string)) < strlen($string))
        return 1;
        else
        return 0;
    }





$string="hello this is string";

echo is_html($string);



$string="hello <strong>this is string</strong>";

echo is_html($string);

?>

Check email validation with Preg_Metch

<?php


//// check email validation with  preg_metch




function checkEmail($email){
  return preg_match('/^\S+@[\w\d.-]{2,}\.[\w]{2,6}$/iU', $email) ? TRUE : FALSE;
}



?>

Check given number is positive and number of digits

<?php

// check number is greater than 0 and $length digits long
  // returns 1 on success
  function isNumberlength($num, $length){
  if($num > 0 && strlen($num) == $length)
  
    return 1;
    else
    return 0;
}



/// call the function with your  values








echo isNumberlength(100,5);



?>

Convert an object to an array with php

<?php



    /**
    *
    * Convert an object to an array
    *
    * @param    object  $object The object to convert
    * @reeturn      array
    *
    */



    function objectToArray( $object )
    {
        if( !is_object( $object ) && !is_array( $object ) )
        {
            return $object;
        }
        if( is_object( $object ) )
        {
            $object = get_object_vars( $object );
        }
        return array_map( 'objectToArray', $object );
    }


    /*** convert the array to object ***/

 //    $array = objectToArray( $obj );

    /*** show the array ***/



  //  print_r( $array );




?>

Check curl is install or on at your server with php

<?php





///  check curl is install or on at your server with php
function iscurlinstalled()
{
    if  (in_array  ('curl', get_loaded_extensions())) {
        return true;
    }
    else{
        return false;
    }
}









?>

Thursday, December 5, 2013

Downalod any file with php

<?php
///Downalod any file with php


function downloadFile($filename)
    {
        header("Content-disposition: filename=".$filename."");

        header("Content-type: application/octetstream");
       
        header("Pragma: no-cache");
       
        header("Expires: 0");
       
    }
   
    $filename='test.doc';
    downloadFile($filename);
   
    ?>

filter_var function in php

<?php

      // The filter_var() function Returns the filtered data TRUE on success or FALSE on failure.
     $emailid='test@test.com';
        if(!filter_var($emailid, FILTER_VALIDATE_EMAIL))
        {
           echo("E-mail ID is Invalid");
        }
       else
        {
             echo("E-mail ID is valid ");
       }
?>

Check e-mail address is valid with php

<?php

  // Check e-mail address is valid with php
         $email=$_POST['email'];
          if (!preg_match("/^([a-zA-Z0-9])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-] +)+/",$email))
            {
                  echo "Email Address Is Invalid !";
            }
          else
           {
                 echo "Email Address Is Valid !";
           }
          

?>

Check IP address by Host Name or Site url

<?php


/// get IP address by Host Name or   site url

 $ip_address = gethostbyname("www.google.com");

 echo "Your  Site IP address :". $ip_address;
?>

Check Password is Strong or weak with php

<?php


$password = "Fyfjk34sdfjfsjq7";

if (preg_match("/^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).*$/", $password)) {
    echo "Your passwords is strong.";
} else {
    echo "Your password is weak.";
}

?>

Redirect to page with php & javascript

/////// Redirect to  any page

function redirectToPage($page)
{

 if($page!="")
 {
    echo "<script>window.location='".$page."';</script>";
 }

}


//////////////////////// example//////////////////


redirectToPage('home.php');