Re: RIGHT Function?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



At 12:33 PM -0700 9/24/09, sono-io@xxxxxxxxxxxxx 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

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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux