Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Firewords

Classe completa de BBCodes

Recommended Posts

Criei essa classe aqui para o meu site, se quiserem usar, a vontade. ^^

 

Aqui você tem as Tags: b, i, u, s, left, right, center, code, quote e img.

 

bbcodes.php

<?php//-------------------------------------// Script criado por Firewords// http://www.firestorm.com.br//-------------------------------------class BBCodes{	var $bbcodes = array( 						  'b' => 'strong',						  'i' => 'em',						  'u' => 'div style="text-decoration:underline"',						  's' => 'div style="text-decoration:line-through"',						  'left' => 'div style="text-align:left"',						  'right' => 'div style="text-align:right"',						  'center' => 'div style="text-align:center"',						);		//-------------------------	// Função que substitui	// todas tags em BBCodes	//-------------------------		function Subs($str="")	{		// Retirando whitespace do inicio da String		$str = ltrim($str);		// Retirando whitespace do final da String		$str = rtrim($str);				// Invalidando HTML		$str = str_replace("<", "<", $str);		$str = str_replace(">", ">", $str);				// Substituindo \n por <br />		$str = str_replace("\n", "<br>", $str);				// Processando BBCodes da variável		foreach($this->bbcodes as $k=>$v)		{			// Substituindo BBCodes por HTML			$str = preg_replace("#\[".$k."\](.*?)\[/".$k."\]#i", "<".$v.">\\1</".$v.">", $str);		}				// Tag [code]		$str = preg_replace("#\[code\](.*?)\[/code\]#ies", "\$this->TagCode('\\1')", $str);				// Tag [quote]		$str = preg_replace("#\[quote\](.*?)\[/quote\]#ies", "\$this->TagQuote('\\1')", $str);				// Tag [img=		$str = preg_replace("#\[img\](.+?)\[/img\]#ie", "\$this->TagImg('\\1')", $str);				// Retornando a String final		return $str;	}		//-------------------------	// Função que substitui a	// Tag [code]	//-------------------------	function TagCode($txt="")	{		// Retornando se texto estivar vazio		if( $txt == "" ) 			return;				// Substituindo Caracters		$txt = str_replace("\\\\\"", "\"", $txt);		$txt = str_replace("\\\\", "\\", $txt);		$txt = preg_replace("/<br>|<br \/>/", "\n", $txt);		$txt = ltrim($txt);		$txt = rtrim($txt);		// ------------------- \\		// Topo		$div[1] = "<div style=\"margin:5px 20px 20px;\"><font size=2>Código:</font>		<div style=\"border:#3F433D 2px double; width:70%; padding:5px 5px 5px 5px; white-space:pre\">";		// Fechando Tags		$div[2] = "</div></div>";		// ------------------- \\				// Colocando Div no Texto		$txt = $div[1].$txt.$div[2];				// Retornando String final		return $txt;	}		//-------------------------	// Função que substitui a	// Tag [quote]	//-------------------------	function TagQuote($txt="")	{		// Retornando se texto estivar vazio		if( $txt == "" )			return;					// Substituindo Caracters		$txt = str_replace("\\\\\"", "\"", $txt);		$txt = str_replace("\\\\", "\\", $txt);				// tirando espals em branco		$txt = preg_replace("/<br>|<br \/>/", "\n", $txt);		$txt = ltrim($txt);		$txt = rtrim($txt);		$txt = str_replace("\n", "<br />", $txt);				// ------------------- \\		// Topo		$div[1] = "<div style=\"margin:5px 20px 20px;\"><font size=2>Citação:</font>		<div style=\"border:#3F433D 2px double; width:70%; padding:5px 5px 5px 5px;\">";		// Fechando Tags		$div[2] = "</div></div>";		// ------------------- \\				// Colocando Div no Texto		$txt = $div[1].$txt.$div[2];				// Retornando String final		return $txt;	}		//-------------------------	// Função que substitui a	// Tag [img]	//-------------------------	function TagImg($img="")	{		$img2 = "[img]".$img."]";				// Retornando se a Tag estiver vazia		if(! $img )			return $img2;					// Tirando espaços vazios		$img = trim($img);				// Verificando se é uma imágem		if (($pos = strrpos($img, ".")) === FALSE)		{			return $img2;		}								$url = str_replace( " ", "%20", $url );				list($width, $height, $type, $attr) = @getimagesize($img);				return "<img src=\"$img\" width=\"$width\" height=\"$height\" alt=\"IMG\" />";	}}?>
teste.php

<?include('bbcodes.php');// Criando Objeto$bbcodes = new BBcodes;// Verificando se o Texto foi enviadoif( isset($_POST['Texto']) ){	// Substituindo BBCodes	$str = $bbcodes->Subs($_POST['Texto']);	// Mostrando	echo $str."<hr />";}?><form action="<?= $_SERVER['PHP_SELF'] ?>" method="post">  <textarea cols="50" rows="10" name="Texto"></textarea>  <br /><br />  <input type="submit" value="Enviar"></form>
http://forum.imasters.com.br/public/style_emoticons/default/thumbsup.gif

Compartilhar este post


Link para o post
Compartilhar em outros sites

Muito bom cara,Vai ajuar muitaaaaa gente!Obs:Precisa colocar os seus créditos nos códigos?-=-=-=-=-=-=--==-=-==--==-=-=-=-=-==-=-=-Cara acabei de testar deu esse erro no teste.php:Notice: Undefined index: Texto in c:\arquivos de programas\easyphp1-7\www\post.php on line 7

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.