At 3:38 PM -0400 3/11/09, Robert Cummings wrote:

Just because I'm a nice guy... :)

Yeah, me too -- here are three routines I use for cutting the right, left and middle portions of strings. These were keyword routines I used in FutureBasic -- they seemed to make sense to me so I carried them into php.

<?php

// ====== returns the right-most number of characters from a string
// $string = "123456789"
// right($string, 3) returns "123"

function right($string, $length)
        {
        $str = substr($string, -$length, $length);
        return $str;
        }

// ====== returns the left-most number of characters from a string
// $string = "123456789"
// left($string, 3) returns "789"

function left($string, $length)
        {
        $str = substr($string, 0, $length);
        return $str;
        }

// ====== returns the middle number of characters from a string starting from the left
// $string = "123456789"
// mid($string, 3, 4) returns "4567"

function mid($string, $left_start, $length)
        {
        $str = substr($string, $left_start, $length);
        return $str;
        }
?>

Cheers,

tedd
--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to