PHP

40 Most Needed Drupal Modules

Here are my top 40 Drupal modules that seem to happen more often I am using them in my Drupal projects.

   1. addtoany
   2. blocks404
   3. boost
   4. cacherouter
   5. canonical_url
   6. captcha
   7. cck
   8. custom_breadcrumbs
   9. date
  10. diggthis
  11. filefield
  12. gravatar
  13. htmlpurifier
  14. image_caption
  15. image_fupload
  16. imageapi
  17. imagecache
  18. imagecache_profiles
  19. imagefield
  20. imagefield_crop
  21. imagefield_tokens
  22. imce
  23. imce_wysiwyg
  24. menu_breadcrumb
  25. montharchive
  26. nodewords
  27. page_title
  28. pathauto
  29. seo_checklist
  30. tagadelic
  31. taxonomy_breadcrumb
  32. taxonomy_manager

Convert Linux/Unix timestamp to human readable format in PHP

This functin will help to convert the Linux/Unix timestamp to human readable format:

<?php
function unix_timestamp_to_human ($timestamp ""$format 'D d M Y - H:i:s')
{
    if (empty(
$timestamp) || ! is_numeric($timestamp)) $timestamp time();
    return (
$timestamp) ? date($format$timestamp) : date($format$timestamp);
}

$unix_time "1251208071";

echo 
unix_timestamp_to_human($unix_time); //Return: Tue 25 Aug 2009 - 14:47:51 
?>

Microsoft Word Document HTML Cleanup in PHP


I had to cleanup a HTML created out of MS Word Document manually.  Honestly it is a pain to manually search and replace all the junks Word Document generating.  So I have written a text conversion function in PHP to automatically cleanup the MS Word junks and output HTML entities.

How to install YUM, Zend Optimizer, eAccelerator and APC

Recently a friend had difficulty installing Alternative PHP Cache (APC) and upload progress for his Drupal CMS on Debian VPS. Therefore I tought of sharing this post about how to setup and run your virtual private server with most useful PHP packages.

I would assume you have a Debian VPS, CentOs or Ubuntu and you would like to install APC, Zend Optimizer and eAccelerator for the best PHP performances or if they are required by some third party applications.

I normally like to install everything on Debian, CentOs or Ubuntu using the yum (Yellow dog Updater, Modified) package manger to make sure that updates for all applications are uniform and its easy to do, easy to search for available packages and easier to type instead of apt-get.

Simple PHP function to generate a random string based on Alpha, Numeric, Nozero, MD5 and SHA1 type

Here's a simple function to generate a random string based on Alpha, Numeric, Nozero, MD5 and SHA1 types.

PHP reverse function strrev() and it's alternative

If you ever wondered how to reversing a string using PHP reverse function “strrev()” and write your own function doing the same thing? Oddly I was asked to write my own PHP function to reverse a string and I though to sharing it.

PHP Header() Function - Force header for a file to download in PHP

This either in PHP will help you to sends the files:
<?php

$file 
'folder/yourfile.zip' //Any file *.*

if (! file) {
    die(
'file not found'); //Or do something 
} else {
    
// Set headers
    
header("Cache-Control: public");
    
header("Content-Description: File Transfer");
    
header("Content-Disposition: attachment; filename=$file");
    
header("Content-Type: application/octet-stream");
    
header("Content-Transfer-Encoding: binary");
    
// Read the file from disk
    
readfile($file); 
}

?>

Simple PHP Text Limiter Function

This function will limited a text string to a given word limit.


<?php
function string_limiter($string$limit 50$end_char '&#8230;')
{
        if (
trim($string) == '')
        {
                return 
$string;
        }

        
preg_match('/^\s*+(?:\S++\s*+){1,'.(int) $limit.'}/'$string$matches);

        if (
strlen($string) == strlen($matches[0]))
        {
                
$end_char '';
        }

        return 
rtrim($matches[0]).$end_char;
}
?>

Example:

Persian Calendar

Persian Calendar in Facebook

 

The Iranian calendar or Solar Hijri is an astronomical solar calendar and one of the longest chronological records in history and is currently used as the official calendar of Iran. It is used in Afghanistan and is one of the alternative calendars used in the neighbor regions such as Kazakhstan and Tajikistan.