Index: functions-formatting.php
===================================================================
--- functions-formatting.php	(revision 3767)
+++ functions-formatting.php	(working copy)
@@ -3,12 +3,14 @@
 function wptexturize($text) {
 	$output = '';
 	// Capture tags and everything inside them
-	$textarr = preg_split("/(<.*>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
-	$stop = count($textarr); $next = true; // loop stuff
+	$textarr = preg_split("/(<[^>]+>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE);
+	$stop = count($textarr); $skip = false; // loop stuff
+	
 	for ($i = 0; $i < $stop; $i++) {
 		$curl = $textarr[$i];
+		$matches = Array();
 
-		if (isset($curl{0}) && '<' != $curl{0} && $next) { // If it's not a tag
+		if (! $skip && isset($curl{0}) && '<' != $curl{0}) { // If it's not a tag
 			$curl = str_replace('---', '&#8212;', $curl);
 			$curl = str_replace(' -- ', ' &#8212; ', $curl);
 			$curl = str_replace('--', '&#8211;', $curl);
@@ -35,12 +37,14 @@
 
 			$curl = preg_replace('/(\d+)x(\d+)/', "$1&#215;$2", $curl);
 
-		} elseif (strstr($curl, '<code') || strstr($curl, '<pre') || strstr($curl, '<kbd' || strstr($curl, '<style') || strstr($curl, '<script'))) {
-			// strstr is fast
-			$next = false;
-		} else {
-			$next = true;
+		} 
+		// skip anything inside these tags
+		elseif (! $skip && preg_match('/^<(code|pre|kbd|style|script|samp)/i', $curl, $matches) ) {
+		  $skip = $matches[1];
 		}
+		elseif ($skip && preg_match("/^<\/$skip/i", $curl)) {
+		  $skip = false;
+		}
 		$curl = preg_replace('/&([^#])(?![a-zA-Z1-4]{1,8};)/', '&#038;$1', $curl);
 		$output .= $curl;
 	}

