PHP toalpha and toalphanum

These aren’t default functions but I thought I’d post them:

<?php

	function toalphanum( $string ) {
		$newstring = "";
		for( $i = 0; $i < strlen( $string ); $i++ ) {
			if( ( ( $string[$i] >= "A" ) && ( $string[$i] < = "z" ) ) || ( ( $string[$i] >= "0" ) && ( $string[$i] < = "9" ) ) ) {
				$newstring[$i] = $string[$i];
			} else {
				$newstring[$i] = "_";
			} // end if
		} // end for
		return implode( "", $newstring );
	} // end toalphanum

	function toalpha( $string ) {
		$newstring = "";
		for( $i = 0; $i < strlen( $string ); $i++ ) {
			if( ( $string[$i] >= "A" ) && ( $string[$i] < = "z" ) ) {
				$newstring[$i] = $string[$i];
			} else {
				$newstring[$i] = "_";
			} // end if
		} // end for
		return implode( "", $newstring );
	} // end toalpha


?>

Nothing brilliant but I find it useful all over the place.

By Lilithe

Dork.