Wednesday, 7 May 2014

check valid Extension in php

<?php
$allowed_ext = array(
             'jpg'    =>    true,
            'gif'    =>    true,
            'png'    =>    true
     );

    function easy_checkvalid_ext($ext,$allowed_ext)
    {
     
     if($allowed_ext[$ext])
        {
            return true;
        }
       else
        {
           return false;
       }  
    
       }

 $validfile = easy_checkvalid_ext('jpg',$allowed_image_format);

if ( !$validfile)
echo "not a valid file type";
?>

Get country code by ip address in php

<?php

function get_easy_visitor_country($ip_address)
{
    if (!$ip_address)
     $ip_address=$_SERVER['REMOTE_ADDR'];
   
     $geopluginURL='http://www.geoplugin.net/php.gp?ip='.$ip_address;
     $addrDetailsArr =@unserialize(file_get_contents($geopluginURL));
      easy_debug($addrDetailsArr);
     $result=$addrDetailsArr['geoplugin_countryCode'];
    return $result;
}


function easy_debug($obj)
{

echo "<pre>";
     print_r(  $obj);
     echo "</pre>";
 
}

?>

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 );




?>
Freelance Jobs