Use this to get something like: “5 bananas”, “1 turtle”. E.g. spnum(5, ‘banana’);
// Support for singular and plural string variations
function spnum($int, $singular, $plural = NULL) {
	if (!is_int($int) || !is_string($singular)) {
		$int = intval($int);
		$singular = strval($singular);
	}
	if ($plural == NULL || !is_string($plural)) {
		$plural = $singular . 's';
	}
	return $int . ' ' . (($int == 1) ? $singular : $plural);
}
Here’s a quick function to search a string for the position of several string occurrences. Once one is found, it returns the position.
// strpos with an array of $needles
function strposa($haystack, $needles) {
	if (is_array($needles)) {
		foreach ($needles as $str) {
			if (is_array($str)) {
				$pos = strposa($haystack, $str);
			} else {
				$pos = strpos($haystack, $str);
			}
			if ($pos !== FALSE) {
				return $pos;
			}
		}
		return FALSE;
	} else {
		return strpos($haystack, $needles);
	}
}
This function will test if any of the strings in an array is equal to a given string. You can specify case sensitivity.
// tests if $needle is equal to any strings in $haystack
function str_equal_array($needle, $haystack, $case_insensitive = TRUE) {
	if (!is_string($needle) || !is_array($haystack)) {
		return FALSE;
	}
	if ($case_insensitive) {
		$needle = strtolower($needle);
	}
	foreach ($haystack as $hay) {
		if (!is_string($hay)) {
			continue;
		}
		if ($case_insensitive) {
			$hay = strtolower($hay);
		}
		if ($needle == $hay) {
			return TRUE;
		}
	}
	return FALSE;
}
Last semester we made a Java game using the Slick library for our project called Shadow Wing. I’ve packaged the game in a single zip, all you need is to have the Java Runtime Environment installed on your computer and then run the .exe inside the zip. If you’re on a Mac or Linux machine, you can run the .jar as long as you set the max memory heap to something like 128MB, otherwise the game dies after it fills the available memory. This wasn’t a problem on my Mac, but I had to make custom exe’s for Windows because the default memory heap was lower. In case the game doesn’t start you can always set your heap larger (say min 32 to max 128MB) with:
java -Xms32m -Xmx128m -jar shadow_wing.jar
The source is also available at GitHub. Anyway, enjoy the game!
This will show you how to package all your java class files into a single executable jar file and how to make it runnable when you double click it. In our project we might need to load external resources like images from subfolders and other .jar libraries like slick.jar and lwjgl.jar. I used the eclipse IDE to develop my project. 1. Once you’ve got it working in eclipse, right click the root folder of your project in the Package Explorer and choose Export, then Java > Runnable JAR file. 2. Choose the option that says “extract required libraries into generated JAR”, choose a directory to export and click finish, accept the warning message if you get any. I’ll be using the name jarFile.jar in this example. 3. Now we need to make sure than any other subfolders folders in your project, like /images or /sounds or anything else you had are included. Copy all of these subfolders into the same folder as the .jar file you made. Ensure that all the external libraries files (.dll and .so, etc) that you need are also included. Just as you copied the subfolders, copy all these library files into the same directory as the .jar file. 4. Double click your .jar file now, it should be runnable as long as it can find all the files it needs to run. Run it in the command line to see if there are any errors:

java -jar jarFile.jar

Making A Runnable EXE File

5. If you want to make an exe file for Windows to run your .jar, you can use a handy free tool called exej. Note that if you have the Java Runtime installed in Windows, you can just double click a .jar to run it, however if you want to add extra runtime arguments like changing the classpath or changing the size of the memory heap available for your program, exej makes that possible. 6. Download exej and extract the files in the zip to another folder than the jar file. 7. Inside the folder with exej.exe, there will be a text file called config.txt. Edit the file and change the command line arguments that you want, make sure that you have ”-jar jarFile.jar” at the end so that the exe knows what jar file to execute with the arguments. In this example, I increase the maximum heap size to 128MB. You can add any of the regular java arguments as you would in the command line.

commandline= -Xms32m -Xmx128m -jar jarFile.jar

Also make sure that you rename jarFile.jar to your .jar filename. 8. Now run make.bat, which is also in the exej folder, to make your exe files with config.txt. It will make two, one that runs java (with command line window) and javaw (without command line window). 9. Finally, all is done, copy these exe files into the same folder you put your .jar file, the subdirectories, and all the other .dll and .so library files you had. Run either of the exe files to test your program. You can, as usual, just run the .jar file by double clicking it, but this won’t have the arguments we made with exej, you’ll need to run it through the command line as usual with something like:

java -Xms32m -Xmx128m -jar jarFile.jar

Anyway, if you’ve got any problems, leave a comment below.