Pages

Monday, 25 November 2013

Date format change by php code

For software development we need different types of date format.

We can do it by a simple line of code. There is an example below:
$cdate = '2013-10-25';  // Y-m-d format
$rdate = date("d-m-Y",strtotime($cdate));  // d-m-Y format
echo $rdate;
I think it will help you.

Tuesday, 12 November 2013

Take difinite number of word from a string

The following function is for to take a definite number of words from an string:

function take_definite_number_word( $words = 10)
{
     $wordCount = count(explode("",$item->description));      // count by space
     if ($wordCount<$words)
    {
            $adjustedText = $item->description;
     }
     else
    {
          $adjustedText = implode(" ", array_slice(explode(" ",$item->description), 0, $words));
    }
}