All pastes #162213 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-09-06 07:53 UTC
rendered paste body
<pre><?

/* 
	HTML2BBCODE 
	HTML kodunu BBCODE etiketlerine cevirir
	@Yns - http://yns.zaxaz.com
*/ 

class html2bbcode {

	/* Replacer Function */
	function getReady($text) {
		$text = preg_replace("|<b>|i","[B]",$text);
		$text = preg_replace("|</b>|i","[/B]",$text);
		$text = preg_replace("|<strong>|i","[B]",$text);
		$text = preg_replace("|</strong>|i","[/B]",$text);
		$text = preg_replace("|<i>|i","[I]",$text);
		$text = preg_replace("|</i>|i","[/I]",$text);
		$text = preg_replace("|<strike>|i","[S]",$text);
		$text = preg_replace("|</strike>|i","[/S]",$text);
		$text = preg_replace("|<h1>|i","[H1]",$text);
		$text = preg_replace("|</h1>|i","[/H1]",$text);		
		$text = preg_replace("|<h2>|i","[H2]",$text);
		$text = preg_replace("|</h2>|i","[/H2]",$text);
		$text = preg_replace("|<h3>|i","[H3]",$text);
		$text = preg_replace("|</h3>|i","[/H3]",$text);
		$text = preg_replace("|<h4>|i","[H4]",$text);
		$text = preg_replace("|</h4>|i","[/H4]",$text);		
		$text = preg_replace("|<h5>|i","[H5]",$text);
		$text = preg_replace("|</h5>|i","[/H5]",$text);
		$text = preg_replace("|<h6>|i","[H6]",$text);
		$text = preg_replace("|</h6>|i","[/H6]",$text);
		$text = preg_replace("|<sup>|i","[SUP]",$text);
		$text = preg_replace("|</sup>|i","[/SUP]",$text);
		$text = preg_replace("|<sub>|i","[SUB]",$text);
		$text = preg_replace("|</sub>|i","[/SUB]",$text);
		$text = preg_replace("|<code>|i","[CODE]",$text);
		$text = preg_replace("|</code>|i","[/CODE]",$text);
		$text = preg_replace("|<pre>|i","[PRE]",$text);
		$text = preg_replace("|</pre>|i","[/PRE]",$text);
		$text = preg_replace("|<blackqoute>|i","[QUOTE]",$text);
		$text = preg_replace("|</blackqoute>|i","[/QUOTE]",$text);
		$text = preg_replace("|<div align=\"left\">|","[LEFT]",$text);
		$text = preg_replace("|</div>|i","[/LEFT]",$text);
		$text = preg_replace("|<div align=\"right\">|i","[RIGHT]",$text);
		$text = preg_replace("|</div>|i","[/RIGHT]",$text);
		$text = preg_replace("|<div align=\"center\">i|","[CENTER]",$text);
		$text = preg_replace("|</div>|i","[/CENTER]",$text);
		$text = preg_replace("|<div align=\"justify\">|i","[JUSTIFY]",$text);
		$text = preg_replace("|</div>|i","[/JUSTIFY]",$text);
		$text = preg_replace("|<ul>|i","[LIST]",$text);
		$text = preg_replace("|</ul>|i","[/LIST]",$text);
		$text = preg_replace("|<ol>|i","[LIST1]",$text);
		$text = preg_replace("|</ol>|i","[/LIST1]",$text);

		/* Define attributes for supported bb-code tags */
		$urlATR = preg_match_all("|<a.*title=['\|\"](.*)['\|\"].*>|iU",$text,$returnText);

		/* $returnText[1] = title value */
		for( $i=0; $i < count($returnText[1]); $i++ ) {
		$ad = array();
			if(!empty($returnText[1][$i]))  {
				//$text  = preg_replace("|<a href=\"([^\"]*)\"</a>|i","[URL HREF=\"$1\"]$3[/URL]",$text);
				$add[0] = " TITLE=\"\$2\"";
				$add[1] = 'title=\"([^\"]*)\';
			}
			else {
				$add[0] = "";
				$add[1] = "";
				
			}
			$text  = preg_replace("|<a href=\"([^\"]*)\" $add[1]>(.*?)</a>|i","[URL HREF=\"$1\" $add[0]]$3[/URL]",$text);
		}
		echo $text;
	}
}

$x = new html2bbcode;
$text = ' <a href="adres" title="ehe44">s</a>  <a href="adres" title="ehe44sd">s</a>  <a href="adres" title="">ehe</a> 


<i>ehe</i> <i>ehe</i><b>ohe</b> <strong>eaheh</strong>';

$x->getReady($text);

?>