<?php

	include("./function.php");

	include( "./convert.php");

	

	$sStr = "-BRcode<BR>[[*<BR>**:html]] <BR>--n code<BR>[[da\n aa:html]]sdaadadadaaddadad";

	$value = $sStr;

	$sOut = "";

	

	$hit = preg_match_all( "/([^\x80-\xff]{0,1})\[\[((?:(?!\[\[).)+):html\]\]/", $sStr, $matches);

	$sMsgOut = "";

	if( $hit > 0){

		//	分割

		for( $i=0; $i<$hit; $i++){

			//	$matches[0][$i] がHTMLルールにヒットした文字列部分

			list( $aMsgTemp[$i], $dummy) = explode( $matches[0][$i], $sStr);

			// <BR>とかの変換

			$sStr = $dummy;

		}

		$aMsgTemp[$hit] = $sStr;

		// 一度HTML部分を他の文字に変換して1行作る。

		$sMsgWikiTemp = "";

		for( $i=0; $i<$hit; $i++){

			$sMsgWikiTemp .= $aMsgTemp[ $i] ."<!HTML".$i."!>";

		}

		$sMsgWikiTemp .= $aMsgTemp[ $hit];

		//	そんで HTMLストリング変換をまとめてかける。

//		$sConvert = sEncodeStr( $sMsgWikiTemp);

		$sConvert = $sMsgWikiTemp;

		$sMsgWikiTemp = $sConvert;

		//	$sMsgWikiTemp にHTMLストリング変換済みの文字列が入っている。

		//	これにHTML分割部分を戻す

		for( $i=0; $i<$hit; $i++){

			$sConvert = preg_replace( "/<!HTML$i!>/", $matches[1][$i].$matches[2][$i], $sMsgWikiTemp);

			$sMsgWikiTemp = $sConvert;

		}

		//	EUC＞SJIS変換

		$sMsgOut = mb_convert_encoding( $sMsgWikiTemp."\n", "SJIS", "EUC-JP");

//		$sMsgOut = $sMsgWikiTemp;

		$sMsg = $sMsgOut;

	}

	

//	echo $sOut;

	

//	echo "<BR><BR>". mb_convert_encoding( $sMsg, "SJIS", "EUC-JP");

//	echo "<BR><BR>". mb_convert_encoding( sEncodeStr($sMsg), "SJIS", "EUC-JP");

//	echo "<BR><BR>". wikiConvert( mb_convert_encoding( sEncodeStr($sMsg), "SJIS", "EUC-JP"));

	

	$urlTemp = 'http://' . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI];

	preg_match( "/([a-zA-Z]+)\.php(.*)/", $urlTemp, $urlmt);

	

	

	echo $urlmt[0];

	

	echo "<BR><BR>". $value;

	echo "<BR><BR>". $sMsg;

	

	echo "<BR><BR>1- ". $matches[2][0];

	echo "<BR><BR>2- ". $matches[2][1];

	

?>