PHP Code
//Purpose
//	Used to convert an ASCII String to an Integer.
//Parameters
//	MyString (String) = The string to convert.
//	Default (Optional Integer) = The value to return if
//		the specified ASCII string is not convertable to an Integer.
//		This type is cast to an Integer using the (integer) command, so, if it enters as any type
//			other than an Integer, it is converted using standard PHP rules for (integer) casting.
//		Default value: 0 (zero)
//Return (Integer)
//	Returns the specified string as an Integer.
//	If the specified string contains a decimal value, it is disregarded (no rounding takes place).
//	Function returns zero if:
//		- the specified string is zero-length, or
//		- the first character of the specified string is a decimal point (".123"), or
//		- the first two characters of the specified string are a minus sign and a decimal point ("-.123"), or
//		- the first two characters of the specified string are a plus sign and a decimal point ("+.123"), or
//		- all characters between a leading minus sign and a decimal point are zeros (-000.123), or
//		- all characters between a leading plus sign and a decimal point are zeros (+000.123).
//	Function returns the specified default value if:
//		- the value contains any characters other than "0123456789.+-" (whether before or after the decimal), or
//		- the value is less than -2,147,483,648, or
//		- the value is greater than 2,147,483,647, or
//		- the value contains more than one decimal point, or
//		- the value contains a minus sign (-) in any position other than the beginning, or
//		- the value contains a plus sign (+) in any position other than the beginning.
//	Additional considerations
//		There can be any number of leading zeros.
//			They are all ignored and will not affect the returned value.
//			Examples:	0000000000000123 = 123
//						-00000000000000000000000123.456 = -123
//		There can be any number of digits after the decimal.
//			They are all ignored and will not affect the returned value.
//			Example:	123.983983897438778432764328723487 = 123
//						-123.000000000000000000000000000000000000005 = 123
//Notes
//	The specified string stores a string of ASCII characters representing an Integer.
//		This is an example of an "ASCII" Integer with a value of 12:
//			(0) 48 "0"   (1) 48 "0"   (2) 49 "1"   (3) 50 "2"
//		Note that the LSB is the one with the highest index.
//Version History
//	1.0 6/30/2004 Tested by Russ Tanner on PHP 4.3.6
function AsInteger_String_ASCII($MyString, $Default = 0) {

	//Initiate variables
	$X = ''; // String buffer for returned Integer (before being converted to an Integer)

	// Set the default return value
	$RetDefault = (integer) $Default;

	// Get the length of the specified string
	$eCount = strlen($MyString);

	// Trap: The specified string is zero-length, this is a valid zero value, return zero and exit now
	if ($eCount == 0) { return (integer) 0; }

	// Main loop: Build a numeric string from the ASCII characters of the specified string
	for ($C = 0; $C < $eCount; $C++) {

		// Error Trap: The current character is invalid, return the default value and exit now
		if (strpos('0123456789.-+', substr($MyString, $C, 1)) === False) { return $RetDefault; }

		// Error Trap: The specified value contains more than one decimal point, return the default value and exit now
		if (substr($MyString, $C, 1) == '.' && strpos($X, '.') !== False) { return $RetDefault; }

		// Error Trap: The specified value contains a minus sign (-) within (not before) it, return the default value and exit now
		if (substr($MyString, $C, 1) == '-' && $C > 0)  { return $RetDefault; }

		// Error Trap: The specified value contains a plus sign (+) within (not before) it, return the default value and exit now
		if (substr($MyString, $C, 1) == '+' && $C > 0)  { return $RetDefault; }

		//The current character is valid, append it to the string accumulator
		$X = $X . substr($MyString, $C, 1);

	}

	// The specified value has a decimal, trim it off (no rounding takes place)
	if (strpos($X, '.') !== False) { $X = substr($X, 0, strpos($X, '.')); }

	// At this point, we know we have a series of (only) digits.
	// The series may or may not have a "+" or "-" prefix.

	// Remove all leading zeros from the string (excluding leading minus signs and plus signs)...
	// Get the sign of the sequence, if one exists
	$Y = ''; // String buffer for $X
	$FoundNZ = False; // Flag used to determine if a non-zero character has been found yet
	$eCount = strlen($X); // Get the length of the string now
	for ($C = 0; $C < $eCount; $C++) {
		// Get the current character we're looking at
		$cChar = substr($X, $C, 1);
		// The FoundNZ flag is set, append ALL characters to the output buffer
		if ($FoundNZ == True) { $Y .= $cChar; }
		// The FoundNZ flag is not set
		else {
			// Current character is a non-zero digit or a sign (+/-)
			if (strpos('123456789+-', $cChar) !== False) {
				$Y .= $cChar; // Append it to the output buffer
				// Current character is a non-zero digit, set the FoundNZ flag
				if (strpos('123456789', $cChar) !== False) { $FoundNZ = True; }
			}
		}
	}
	$X = $Y; // Restore the data to the original buffer

	// Trap: The resulting string is either a zero-length string or only a minus sign or only a plus sign,
	// these all represent a valid zero value, return zero and exit now
	if (strlen($X) == 0 || $X == '-' || $X == '+') { return (integer) 0; }

	// Error Trap: The specified value is out of range, return the default value and exit now
	if (strlen($X) > 12) { return $RetDefault; } // Too many characters, value must be out of range (-N,NNN,NNN,NNN.)
	if ((float) $X < -2147483648 || (float) $X > 2147483647) { return $RetDefault; } // Value is out of range
	
	// Cast the specified number to an Integer and return the result
	return (integer) $X;

} 


The Captian
Today they call you "crazy". Tomorrow they call you "ahead of your time."
Global Skywatch Learn about Chemtrails - You're breathing them now!
OnlyTheBestHerbs.com World-class supplements
Mercury Talk Why you are sick.
OneUp Domains Domains, Hosting, Email
1-800-358-4278 (U.S. & Canada)