5 Years ago PHP(Functions) 0(Disable)

If you want to delete everything from folder (including subfolders) use this function.

function removeDir( $dir )
{
   if ( is_dir( $dir ) ) {
      $objects = scandir( $dir );
      foreach ( $objects as $object ) {
         if ( $object != "." && $object != ".." ) {
            if ( filetype( $dir . "/" . $object ) == "dir" ) {
               rrmdir( $dir . "/" . $object );
            }
            else {
               unlink( $dir . "/" . $object );
            }
         }
      }
 
      reset( $objects );
      rmdir( $dir );
   }
 
   return true;
}
 
removeDir( '/foo/' );

5 Years ago(Updated in 5 Years ago) PHP(Functions) 0

Translates a number to a short alhanumeric version. e.g.: 9007199254740989 --> PpQXn7COf
In most cases this is better than totally random ID generators because this can easily avoid duplicate ID's. For example if you correlate the alpha ID to an auto incrementing ID in your database, you're done.
more info on limitation: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/165372
"alphaID maker"

5 Years ago PHP(Functions) 0(Disable)

Escapes special characters in a string for use in an SQL statement. howewer it check get_magic_quotes_gpc function is enable or no. if true , it strips string from slashes and escaped string from special characters in a string for use in an SQL statement.

function sql_escape_string( $str, $conn = '' )
{
   if ( get_magic_quotes_gpc() )
      $str = stripslashes( $str );
   //check if this function exists
   if ( function_exists( "mysql_real_escape_string" ) and $conn )
      $str = mysql_real_escape_string( $str, $conn );
   else
      $str = addslashes( $str ); //for PHP version < 4.3.0 use addslashes
   return $str;
}

5 Years ago(Updated in 5 Years ago) Web(V2 Tools) 0(Disable)

image of ip detector tool

Do you have to find out your IP address? please visit My IP - ip and ip location detector

5 Years ago(Updated in 5 Years ago) PHP(Functions) 0(Disable)

Encrypt function return different value with each execute but decrypt function return input value. for example:
first execute: encrypt('hello') => 'axxdfg34', decrypt('axxdfg34') return 'hello'
second execute: encrypt('hello') => 'xvcfghty214s', decrypt('xvcfghty214s') return 'hello'

5 Years ago(Updated in 5 Years ago) PHP(Functions) 0(Disable)

This function is used to find the file extension also you can use pathinfo() function for get information about a file path.

function ext($file_name)
{
   return substr($file_name, strrpos($file_name, '.') + 1);
}

5 Years ago PHP(Functions) 0(Disable)

The best way to determine the character count of a UTF8 string.

function strlen_utf8( $str )
{
   return mb_strlen( $str, 'UTF-8' );
}
 
//or...
function strlen_utf8( $str )
{
   $c = 0;
   $len = strlen( $str );
   for ( $i = 0; $i < $len; $i++ ) {
      //0x80 = 128
      $ord = ord( $str[$i] );
      if ( $ord & 0x80 ) {
         $ord <<= 1;
         while ( $ord & 0x80 ) {
            $i++;
            $ord <<= 1;
         }
 
         $c++;
      }
      else {
         $c++;
      }
   }
 
   return $c;
}

5 Years ago PHP(Functions) 0(Disable)

This function check if an url is valid or not.

function is_valid_url($url)
{
   return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}

5 Years ago PHP(Functions) 0(Disable)

This way useful for create mixed arguments function.

function foo()
{
    $args = func_get_args();
    print_r($args);
}
 
foo(1, 1256, 6, 17); //mixed ...
 
-------------------Out----------------------
Array
(
    [0] => 1
    [1] => 1256
    [2] => 6
    [3] => 17
)

Loading...