All pastes #2103568 Raw Edit

Unnamed

public text v1 · immutable
#2103568 ·published 2012-01-16 15:15 UTC
rendered paste body
		/**
		 * Extract the last `$num` characters from a string.
		 *
		 * @param string $str
		 *	the string to extract the characters from.
		 * @param integer $num
		 *	the number of characters to extract.
		 * @return string|boolean
		 *	a string containing the last `$num` characters of the
		 *	input string, or false on failure.
		 */
		public static function right($str, $num){
			$str = substr($str, strlen($str)-$num,  $num);
			return $str;
		}


		/**
		 * Extract the first `$num` characters from a string.
		 *
		 * @param string $str
		 *	the string to extract the characters from.
		 * @param integer $num
		 *	the number of characters to extract.
		 * @return string|boolean
		 *	a string containing the last `$num` characters of the
		 *	input string, or false on failure.
		 */
		public static function left($str, $num){
			$str = substr($str, 0, $num);
			return $str;
		}