Monday, 9 December 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, 5 December 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);
   
    ?>
Freelance Jobs