<?
/*
 MSTF
*/
$Content = '
<div class="sinifim">
	içerik başlangıç
	<div class="sinifim">
		içerik başlangıç 2
		<div class="sinifim">
			içerik başlangıç 3
			<div class="sinifim">
				içerik 4
			</div>
			içerik son3
		</div>
		içerik son 2
	</div>
	içerik son
</div>
';

function Get_Tag_Content($Content, $Tag, $Deep = 0)
{
	static $Deep_Counter = 0;
	static $Exit = FALSE;
	
	if($Exit){
		return $Content;
	}

	if(!is_numeric($Deep)){
		trigger_error('Geçersiz derinlik değeri', E_USER_ERROR);
	}

	preg_match("#<$Tag.*>((?:[^<]|<(?!/?$Tag]))+)</$Tag>#", $Content, $o);

	if($Deep_Counter == $Deep){
		$Exit = TRUE;
		return Get_Tag_Content($o[1], $Tag, $Deep);
	}
	
	$Deep_Counter++;

	return Get_Tag_Content($o[1], $Tag, $Deep);
}

echo Get_Tag_Content($Content, 'div', 2);
?>