Re: RIGHT Function?

From: Date: Fri, 25 Sep 2009 11:52:45 +0000
Subject: Re: RIGHT Function?
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-298349@lists.php.net to get a copy of this message
At 12:33 PM -0700 9/24/09, sono-io@fannullone.us wrote:
On Sep 24, 2009, at 12:15 PM, Jay Blanchard wrote:
substr will work from right to left. If your data is in a variable do this;
Thanks, Jay. That does the job. Frank
Frank: I came to this thread a little late, but the following are some functions I use, namely right(), left() and mid(). These were built-in functions in different language I used many years ago. They just seemed natural to me so I wrote them for php. Cheers, tedd ----- <?php // ====== returns the right-most number of characters from a string // $string = "123456789" // right($string, 3) returns "789" 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 "123" 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; } ?> -- ------- http://sperling.com http://ancientstones.com http://earthstones.com

« previous php.general (#298349) next »