[PHP] Ik krijg ubb maar niet aan de praat...

Status
Niet open voor verdere reacties.

Rimsic

Terugkerende gebruiker
Lid geworden
15 jan 2005
Berichten
3.143
Hey ben ik weer is :rolleyes:, ik zit al een tijd te prutsen met ubb en dit heb ik al een keer eerder proberen op te lossen maar elke keer kom ik er maar niet uit!

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN">
<html>

	<head>
		<title>Nieuws Systeem :: REACTIES</title>
	</head>
	<body>
<?php
include ("mysql_connect.php");
$id = (int)$_GET["id"];
$sql = "SELECT id,titel,datum,auteur,bericht FROM nieuws WHERE id = ".$id; 
$result = mysql_query($sql) or die(mysql_error());

while ($obj = mysql_fetch_object($result)) {
echo ("<div><b>Titel:</b> ". $obj->titel . "</div> ");
echo ("<div><b>Datum:</b> ". $obj->datum . "</div> ");
echo ("<div><b>Auteur:</b> ". $obj->auteur . "</div> ");
echo ("<div><b>Volledig Bericht:</b> ". $obj->bericht . "</div> ");
echo ("<br /><br /> ");
}


----------------------------------------------------
-----------------REACTIES LEZEN--------------
----------------------------------------------------


echo ("<h2>Reacties:</h2>");

$r_sql = "SELECT rid,nid,r_naam,r_datum,r_ip,r_bericht FROM reacties WHERE nid = ".$id." ORDER BY nid DESC ;"; 
$r_result = mysql_query($r_sql) or die(mysql_error());

while ($r_obj = mysql_fetch_object($r_result)) {
echo ("<div><b>Naam:</b> ". $r_obj->r_naam . "</div> ");
echo ("<div><b>Datum:</b> ". $r_obj->r_datum . "</div> ");
echo ("<div><b>IP:</b> ". $r_obj->r_ip . "</div> ");
echo ("<div><b>Bericht:</b> ". $r_obj->r_bericht . "</div> ");
echo ("<br /><br /> ");
}

echo ("<div><a href=\"index.php\"> < Terug</a></div><br />");

----------------------------------------------------
-----------------REACTIE TOEVOEGEN---------
----------------------------------------------------

echo ("<h2>Geef je reactie!</h2>");

echo "<html><head><title>Reageer</title></head><body>"; 
echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" style=\"border-collapse:collapse;\">"; 
echo "<form method=\"post\" action=\"".$PHP_SELF."\">"; 
echo "<tr><td width=\"300\">Naam:</td><td width=\"300\"><input type=\"text\" name=\"r_naam\" size=\"20\"></td></tr>"; 
echo "</td><td width=\"300\"><input type=\"hidden\" name=\"r_datum\" >"; 
echo "</td><td width=\"300\"><input type=\"hidden\" name=\"r_ip\" >"; 
echo "<tr><td width=\"300\">Bericht:</td><td width=\"300\"><textarea name=\"r_bericht\" cols=\"40\" rows=\"5\"></textarea></td></tr>"; 
echo "<tr><td width=\"300\"></td><td width=\"300\"><input type=\"submit\" name=\"verzenden\" value=\"Post\">&nbsp<input type=\"reset\" value=\"Velden legen\"></td></tr>"; 
echo "</form></table>"; 

if(isset($_POST['verzenden'])){ //Als er Post is gedrukt dan.... 
    if($_POST['r_naam'] == "" ){// Checken of er een naam is ingevult.. 
        echo "U heeft uw naam niet ingevult";// Als dat niet zo is 
    }if($_POST['r_bericht'] == "" ){ // kijken of er wel een bericht is geplaatst 
        echo "U heeft geen bericht ingevult"; // Als dat niet zo is 
	 
		$r_naam = $_POST['r_naam']; 
		$r_datum = date ("H:i - d M-Y");
		$r_ip = $_SERVER['REMOTE_ADDR'];
        $r_bericht = nl2br($_POST['r_bericht']); 
        $nid = $_GET['id']; 


        $sql = "INSERT INTO reacties (rid, nid, r_naam, r_datum, r_ip, r_bericht) 
		VALUES ('', '".$nid."', '".$r_naam."', '".$r_datum."', '".$r_ip."', '".$input."')";
        $query = mysql_query($sql) or die(mysql_error()); 
        echo "Uw reactie is succesvol toegevoegt"; 


    } 

}
mysql_free_result($result);

?>
	</body>
</html>

Ik heb het al met verschillend ubb parsers geprobeerd :confused: Ik moet eigenlijk alleen de standaard ubb code's zoals:

- vet
- schuin
- onderstreep
- img
- url [url=..]

Mijn tekst komt dus uit een database tabel die tekst heet 'r_bericht' en die zou geparsed moeten worden.

Super bedankt alvast, ik ben er namelijk al heel lang mee bezig....:(
PS: Sorry voor het uitgerekte forum...maar ik moet toch even de code laten zien
 
Geplaatst door masterprut
Wat heb je tot nu toe.
bedoel je daarmee de ubb code? Die heb ik gewoon ergens weg gehaald. De pagina code staat hier boven.

Maar wanneer ik deze code wil gebruiken:
Code:
<?php 
function parseubb($bericht,$quote_color){ 
   $bericht = str_replace ("[br]","\n",$bericht); 
   $bericht = str_replace ("\n","<br>",$bericht); 
   $bericht = str_replace ("","<b>Code:</b><br><table bgcolor=\"#000000\" cellspacing=\"1\" width=\"90%\"><tr><td><table cellpadding=2 cellspacing=\"0\" bgcolor=\"#FFFFFF\" width=\"100%\"><tr><td><font face=Courier size=\"1\" color=\"#000000\">", $bericht); 
   $bericht = str_replace ("", "</font></td></tr></table></td></tr></table>", $bericht); 
   $bericht = str_replace ("[b ]", "<b>", $bericht); // [b ] zonder spatie 
   $bericht = str_replace ("[i ]", "<i>", $bericht); // [i ] zonder spatie 
   $bericht = str_replace ("[u ]", "<u>", $bericht); // [u ] zonder spatie 
   $bericht = str_replace ("[s]", "<s>", $bericht); 
   $bericht = str_replace ("[/b ]", "</b>", $bericht); // [/b ] zonder spatie 
   $bericht = str_replace ("[/i ]", "</i>", $bericht); // [/i ] zonder spatie 
   $bericht = str_replace ("[/u ]", "</u>", $bericht); // [/u ] zonder spatie 
   $bericht = str_replace ("[/s]", "</s>", $bericht); 
   $bericht = str_replace ("[move]", "<div align=\"center\"><marquee width=\"90%\">", $bericht); 
   $bericht = str_replace ("[/move]", "</marquee></div>", $bericht); 
   $bericht = preg_replace ("/\[glow(.*)\](.*)\[\/glow\]/",">> GLOW <<",$bericht); 
   $bericht = preg_replace ("[/glow]","", $bericht); 
   $bericht = preg_replace ("/\[shadow(.*)\](.*)\[\/shadow\]/", ">> SHADOW <<", $bericht); 
   $bericht = preg_replace ("#\[color=(\#[0-9A-F]{6}|[a-z\-]+)\](.*?)\[/color\]#si", "<font color=\"\\1\">\\2</font>", $bericht); 
   $bericht = preg_replace ("/\[font=(.*)\](.*)\[\/font\]/", "<font face=\"$1\">$2</font>", $bericht); 
   $bericht = preg_replace ("/\[size=(.*)\](.*)\[\/size\]/", "<font size=\"$1\">$2</font>", $bericht); 
   $bericht = preg_replace("/[img](.*?)\[\/img\]/si", "<img src=\"\\1\" border=\"0\">",$bericht); 
   $bericht = str_replace ("[tt]", "<tt>", $bericht); 
   $bericht = str_replace ("[/tt]", "</tt>", $bericht); 
   $bericht = str_replace ("[left]", "<div align=left>", $bericht); 
   $bericht = str_replace ("[/left]", "</div>", $bericht); 
   $bericht = str_replace ("[center]", "<div align=\"center\">", $bericht); 
   $bericht = str_replace ("[/center]", "</div>", $bericht); 
   $bericht = str_replace ("[right]", "<div align=\"right\">", $bericht); 
   $bericht = str_replace ("[/right]", "</div>", $bericht); 
   $bericht = str_replace ("[sub]", "<sub>", $bericht); 
   $bericht = str_replace ("[/sub]", "</sub>", $bericht); 
   $bericht = str_replace ("[sup]", "<sup>", $bericht); 
   $bericht = str_replace ("[/sup]", "</sup>", $bericht); 
   $bericht = str_replace ("[fixed]", "<font face=\"Courier New\">", $bericht); 
   $bericht = str_replace ("[/fixed]", "</font>", $bericht); 
   $bericht = str_replace ("[[","{{",$bericht); 
   $bericht = str_replace ("]]","}}",$bericht); 
   $bericht = str_replace ("|","|",$bericht); 
   $bericht = str_replace ("[pre]","<pre>",$bericht); 
   $bericht = str_replace ("[/pre]","</pre>",$bericht); 
   $bericht = str_replace ("{{","[",$bericht); 
   $bericht = str_replace ("}}","]",$bericht); 
   $bericht = str_replace ("[hr]","<hr color=\"#FFFFFF\" noshade />",$bericht); 
   $bericht = eregi_replace("\\[email=([^\\[]*)\\]([^\\[]*)\\[/email\\]", "<a href=\"mailto:\\1\">\\2</a>",$bericht);   
   $bericht = eregi_replace("\\[url=([^\\[]*)\\]([^\\[]*)\\[/url\\]","<a href=\"\\1\" target=_blank>\\2</a>",$bericht); 
   $bericht = preg_replace("/[url](.*?)\[\/url\]/si", "<a href=\"\\1\" target=_blank>\\1</a>",$bericht); 
   $bericht = preg_replace("/\[email\](.*?)\[\/email\]/si", "<a href=\"mailto:\\1\">\\1</a>",$bericht); 
   $bericht = preg_replace ("#\[ftp\]([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/ftp\]#", "<a href=\"ftp://\\1\\2\" target=\"_blank\">\\2</a>", $bericht); 
   $bericht = preg_replace ("#\[ftp\]([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\[/ftp\]#", "<a href=\"ftp://\\1\" target=\"_blank\">\\1</a>", $bericht); 
   $bericht = preg_replace ("#\[ftp=([a-z]+?://){1}([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/ftp\]#", "<a href=\"ftp://\\1\\2\" target=\"_blank\">\\2</a>", $bericht); 
   $bericht = preg_replace ("#\[ftp=([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+\(\)]+)\](.*?)\[/ftp\]#", "<a href=\"ftp://\\1\" target=\"_blank\">\\2</a>", $bericht);   

  $bericht = preg_replace("/\[quote=(.+?)\](.+?)\[\/quote\]/is", '<br><table width="100%" cellspacing="0" cellpadding="0"><tr><td width="5%">&nbsp;</td><td>Quote:</td></tr><tr><td width="5%">&nbsp;</td><td bgcolor=".$quote_color." class="border">$1<br>$2</td></tr></table><br>', $bericht); 

   $bericht = str_replace ("
","<ul>",$bericht); 
   $bericht = str_replace ("[*]","<li>",$bericht); 
   $bericht = str_replace ("
","</li></ul>",$bericht); 
   $bericht = str_replace ("::)","<img src=\"gif/rolleyes.gif\" width=\"15\" height=\"15\" border=\"0\">",$bericht); 
return $bericht; 
} 
?>
(wat smileys verwijderd omdat het beetje on overzichtelijk was.)
Dan staat er dat ik hem zo moet opvragen:
Code:
<?php 
echo parseubb($bericht,$quote_color); 
?>
De 'quote_color' is de achtergrond kleur. Hoe moet ik dit toepassen wanneer ik uit een database 'r_bericht' haal?
 
Status
Niet open voor verdere reacties.
Steun Ons

Nieuwste berichten

Terug
Bovenaan Onderaan