Formular mit BBCODE

Fruitgum

Erfahrenes Mitglied
Hallo Leutz,

Ich habe mir mal vor einiger Zeit ein Formular hier aus den Forum angeschaut, was ich Prima fand. Nur weiß ich nicht mehr von wem. Tschuldigung!

Gut, hier der Code:

Funktions.php
PHP:
<?php
function replacetags($messagetext)
{
while ((strpos($messagetext,"[ url= ")>-1) && (strpos($messagetext,"[ /url ]")>-1))
	{
		$startpos=strpos($messagetext,"[ url=")+5;
		$endpos=strpos($messagetext,"]",$startpos);
		$url=substr($messagetext,$startpos,$endpos-$startpos);
		$startpos=$endpos+1;
		$endpos=strpos($messagetext,"[ /url ]",$startpos);
		$urltext=substr($messagetext,$startpos,$endpos-$startpos);
		$codestring='[ url='.$url.']'.$urltext.'[ /url ]';
		$textstring='<a href="'.$url.'">'.$urltext.'</a>';
		$messagetext=str_replace($codestring,$textstring,$messagetext);
	}
while ((strpos($messagetext,"[ color=")>-1) && (strpos($messagetext,"[ /color ]")>-1))
	{
		$startpos=strpos($messagetext,"[ color=")+5;
		$endpos=strpos($messagetext,"]",$startpos);
		$color=substr($messagetext,$startpos,$endpos-$startpos);
		$startpos=$endpos+1;
		$endpos=strpos($messagetext,"[ /color ]",$startpos);
		$colortext=substr($messagetext,$startpos,$endpos-$startpos);
		$codestring='[ color ]'.$colortext.'[ /color ]';
		$textstring='<font color="'.$color.'">'.$colortext.'</font>';
		$messagetext=str_replace($codestring,$textstring,$messagetext);
	}
while ((strpos($messagetext,"[ b ]")>-1) && (strpos($messagetext,"[ /b ]")>-1))
	{
		$startpos=strpos($messagetext,"[ b ]")+3;
		$endpos=strpos($messagetext,"[ /b ]",$startpos);
		$text=substr($messagetext,$startpos,$endpos-$startpos);
		$codestring='[ b ]'.$text.'[ /b ]';
		$textstring='<b>'.$text.'</b>';
		$messagetext=str_replace($codestring,$textstring,$messagetext);
	}
while ((strpos($messagetext,"[ i]")>-1) && (strpos($messagetext,"[ /i]")>-1))
	{
		$startpos=strpos($messagetext,"[ i]")+3;
		$endpos=strpos($messagetext,"[ /i]",$startpos);
		$text=substr($messagetext,$startpos,$endpos-$startpos);
		$codestring='[ i]'.$text.'[ /i]';
		$textstring='<i>'.$text.'</i>';
		$messagetext=str_replace($codestring,$textstring,$messagetext);
	}
while ((strpos($messagetext,"[ u ]")>-1) && (strpos($messagetext,"[ /u ]")>-1))
	{
		$startpos=strpos($messagetext,"[ u ]")+3;
		$endpos=strpos($messagetext,"[ /u ]",$startpos);
		$text=substr($messagetext,$startpos,$endpos-$startpos);
		$codestring='[ u ]'.$text.'[ /u ]';
		$textstring='<u>'.$text.'</u>';
		$messagetext=str_replace($codestring,$textstring,$messagetext);
	}
while ((strpos($messagetext,"[ s ]")>-1) && (strpos($messagetext,"[ /s ]")>-1))
	{
		$startpos=strpos($messagetext,"[ s ]")+3;
		$endpos=strpos($messagetext,"[ /s ]",$startpos);
		$text=substr($messagetext,$startpos,$endpos-$startpos);
		$codestring='[ s ]'.$text.'[ /s ]';
		$textstring='<s>'.$text.'</s>';
		$messagetext=str_replace($codestring,$textstring,$messagetext);
	}
return $messagetext;
}
?>

Funktions.js:
HTML:
function formattedtext(format)
{
formattext=prompt("Please enter the text to format.\n["+format+"]xxx[/"+format+"]","");
if ((formattext!="") && (formattext!=null))
	{
		document.messageform.text.value=document.messageform.text.value+"["+format+"]"+formattext+"[/"+format+"]";
	}
}

function urltext()
{
urldescription=prompt("Please enter a description for the URL (optional).","")
if (urldescription!=null)
	{
		url=prompt("Please enter the URL.","http://");
		if ((url!="") && (url!=null))
			{
				if (urldescription=="")
					{
						urldescription=url;
					}
				document.messageform.text.value=document.messageform.text.value+"[ url="+url+" ]"+urldescription+"[ /url ]";
			}
	}
}

function colortext(color)
{
formattext=prompt("Please enter the text to format.\nxxx","");
if ((formattext!="") && (formattext!=null))
	{
		document.messageform.text.value=document.messageform.text.value+""+formattext+"";
	}
}

und das Formular:
HTML:
<script src="functions.js" type="text/javascript"></script>
<? include("functions.php"); ?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="messageform" method="post" action="add_eintrag_code.php" enctype="multipart/form-data">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3" bgcolor="#E6E6E6"><strong>Oberen Block erstellen</strong> </td>
</tr>
<tr>
<td width="14%"><strong>Titel:</strong></td>
<td width="2%">:</td>
<td width="84%"><input name="titel" type="text" id="titel" size="50" /></td>
</tr>
<tr>
<td valign="top"><strong>Text:</strong></td>
<td valign="top">:</td>
<button type="button" name="bold" value="bold" onClick="javascript:formattedtext('b');"><b>B</b></button>
<button type="button" name="italic" value="italic" onClick="javascript:formattedtext('i');"><i>I</i></button>
<button type="button" name="underline" value="underline" onClick="javascript:formattedtext('u');"><u>U</u></button>
<button type="button" name="strikeout" value="strikeout" onClick="javascript:formattedtext('s');"><s>S</s></button>
<button type="button" name="url" value="url" onClick="javascript:urltext();">URL</button>
<button type="button" name="red" value="red" onClick="javascript:colortext('#ff0000');"><font color="#ff0000">R</font></button>
<button type="button" name="green" value="green" onClick="javascript:colortext('#00ff00');"><font color="#00ff00">G</font></button>
<button type="button" name="blue" value="blue" onClick="javascript:colortext('#0000ff');"><font color="#0000ff">B</font></button>
<br>
<td><textarea name="text" cols="100" rows="30" id="text" ></textarea></td>
</tr>
<tr>
<td><strong>Bild:</strong></td>
<td>:</td>
<td><input type="file" name="datei" />
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit" /> <input type="reset" name="Submit2" value="Reset" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

Jut! Das alles funktioniert alles Super. Nun möchte ich gern das Formular erweitern mit Aufzählungszeichen und TAB-Funktion. Weiß aber nicht wie ich mit den Code in der funktions.php umgehen soll bzw. erweitern kann.

Wäre tollt wenn mir ein helfen könnte....



Grüße
 
Zurück