Cut string in php

function getlastWords($string, $words = 1)
{
    $string = explode(' ', $string);

    if (count($string) > $words)
    {
        return implode(' ', array_slice($string, 518, $words));
    }

    return implode(' ', $string);
}
-----------------------------------------------------------------------------------------------------------
function getFirstWords($string, $words = 1)
{
    $string = explode(' ', $string);

    if (count($string) > $words)
    {
        return implode(' ', array_slice($string, 0, $words));
    }

    return implode(' ', $string);
}

Comments

Popular posts from this blog

Difference between hook_boot and hook_init Drupal

Difference between DBMS and RDBMS?

Update node in Drupal 7