PHP: function strotolower

Hi,

I have a variable that equals a html page with tags and content between tags. I would like a function that makes everything between < and the first following > lower case.
example: <TABLE BORDER=“1”>PONY</TABLE> to <table border=“1”>PONY</table>

I found this on php.net but it first did the opposite so I changed < to > and vice versa. And it seems to work… But I would like to make sure it’s good code and does exactly what I want. It’s to advanced php for me. Is preg_slit necessary? Do I need to change the order because I switched < and >?

THANKS!

function lowerinsidetags ($str) {
		$chars = preg_split ("//", $str);
		$tolower = true;
		$str = '';
		foreach ($chars as $k) {
		if ($k == '>') { $tolower = false; }
		if ($tolower) { $k = strtolower ($k); }
		$str .= $k;    
		if ($k == '<') { $tolower = true; }
		}
		return $str;
		}