Advertisement
2_2002-2004 Debugging and Error Handling #126997

strrtrim

Removes trailing spaces from the end of a string. See "trim" to remove leading spaces.

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
/* strrtrim : removes trailing spaces from the end of a string*/
static char* strrtrim( char* s)
{
 int i;
 if (s) {
  i = strlen(s); while ((--i)>0 && isspace(s[i]) ) s[i]=0;
 }
 return s;
}
Upload
<?
$countfile = "counter.txt";	// The file where the count is stored. Doesn't have to be created!
$statsfile = "stats.txt";	// The file where the user stats are stored. Doesn't have to be created!
	
/****No need to change anything below here****/
	
if (file_exists($countfile)) { 			// Makes sure the file above exists, if it doesn't, goto else
	$fp = fopen($countfile, "r"); 			// Open the file above ($countfile)
	 $output = fread($fp, filesize($countfile)); 	// Read the file and get the count
	fclose($fp);					// Close the file above
	
	$count = intval($output);			// Make sure the value read from the file ($output) is a number
} 
else { 						// No file was found! These instructions are executed instead
	$count = 0; 					// Set the count to 0 since there was no file
}
	
// This is the function used to add then display the count on your page and to get the stats on the user
function ShowCount() { 
	global $ShowCount, $countfile, $statsfile, $count; // Makes sure the count is displayed on all systems
	
	$month 	= date(m);					// This gets the current month
	$day 	= date(d);					// This gets the current day
	$year 	= date(Y);					// This gets the current year
	$hour 	= date(G);					// This gets the current hour
	$minute	= date(i);					// This gets the current minute
	$second	= date(s);					// This gets the current second
	
	$date = "$month/$day/$year $hour:$minute:$second\n";	// This is the date used in the stats file
	
	$ipaddress = getenv("REMOTE_ADDR");	// This is the user's IP. getenv() is used to get an environment variable
	$otherinfo = getenv("HTTP_USER_AGENT");	// This is other info on the user like their browser and OS platform.
	
	$fp = fopen($statsfile, "a");						// This opens the file as "a", which means it adds to the end
	 fwrite($fp, "IP: $ipaddress | Info: $otherinfo | Date: $date");	// This is the user info being saved.
	fclose($fp);								// Close the file
	
	$count++; 				// Add 1 count
	
	$fp = fopen($countfile, "w"); 		// Open the file above ($countfile)
	 fwrite($fp, $count); 			// Save the new count to the file
	fclose($fp); 				// Close the file above
	 
	$ShowCount = $count; 			// Save the value loaded ($count) as $ShowCount so it can be returned correctly
	return $ShowCount; 			// Tells PHP to return that value
}
?>
Upload
Original Comments (3)
Recovered from Wayback Machine