Kinman
2004-10-18, 00:00:08
Hi, ich bin schon völlig am verzweifeln..
folgende Funktion funzt beim ersten mal einwandfrei aber sobald ich sie ein zweites mal aufrufe, funktioniert sie nicht mehr korrekt...
Sobald ich die IFs vor den schleifen aktivier (also eine while schleife aus der do while mache) funktionierts überalle, aber ineinandergeschachtelte bbcode funzen dann nimmer...
EDIT: Ups funzt nur dann nicht, wenn der BBCode ganz am Anfang steht...
<?php
function BBCode($message)
{
$message = trim($message); //Delete whitespaces in front and at the end of the message
$message = str_replace("\n", "<BR>", $message); //Convert breaks into <BR>
// $message = str_replace(" ", " ", $message); //Convert whitespaces to
$message = str_replace("\\\"", "\"", $message); //Delete the \ in front of a "
$message = str_replace("\'", "'", $message); //Delete the \ in front of a '
$message = str_replace("", "<B>", $message); //Bold text
$message = str_replace("", "</B>", $message); //Bold text
$message = str_replace("", "<B>", $message); //Bold text
$message = str_replace("", "</B>", $message); //Bold text
$message = str_replace("", "<U>", $message); //Underline
$message = str_replace("", "</U>", $message); //Underline
$message = str_replace("", "<U>", $message); //Underline
$message = str_replace("", "</U>", $message); //Underline
$message = str_replace("", "<I>", $message); //Italic text
$message = str_replace("", "</I>", $message); //Italic text
$message = str_replace("", "<I>", $message); //Italic text
$message = str_replace("", "</I>", $message); //Italic text
$message = str_replace("", "", $message); //Image
$message = str_replace("", "", $message); //Image
$message = str_replace("", "<IMG SRC=\"", $message); //Image
$message = str_replace("", "\">", $message); //Image
$message = str_replace("", "", $message); //Code
$message = str_replace("", "", $message); //Code
$message = str_replace("", "<SPAN STYLE=\"font-family: Courier New; font-size: 12px\">", $message); //Code
$message = str_replace("", "</SPAN>", $message); //Code
$message = str_replace("", "", $message); //URL
if (strpos($message,"[URL=") != FALSE)
{
do
{
$URLStartPos = strpos($message,"[URL=");
$URLEndPos = strpos($message,"[/URL]") + 6;
$URLLength = $URLEndPos -$URLStartPos;
$URLString = substr($message, $URLStartPos, $URLLength);
$URLLinkStart = strpos($URLString, "=") + 1;
$URLLinkEnd = strpos($URLString, "]");
$URLLinkLength = $URLLinkEnd - $URLLinkStart;
$URLLink = substr($URLString, $URLLinkStart, $URLLinkLength);
$URLTextStart = strpos($URLString, "]") + 1;
$URLTextEnd = strpos($URLString, "[", $URLTextStart);
$URLTextLength = $URLTextEnd - $URLTextStart;
$URLText = substr($URLString, $URLTextStart, $URLTextLength);
$URL = "<A HREF=\"" . $URLLink . "\" TARGET=\"_blank\" CLASS=text>" . $URLText . "</A>";
$message = str_replace($URLString, $URL, $message);
}
while (strpos($message,"[URL=") != FALSE); //End of URL
}
$message = str_replace("", "", $message); //COLOR
//if (strpos($message,"[COLOR=") != FALSE)
{
do
{
$COLORStartPos = strpos($message,"[COLOR=");
$COLOREndPos = strpos($message,"[/COLOR]") + 8;
$COLORLength = $COLOREndPos -$COLORStartPos;
$COLORString = substr($message, $COLORStartPos, $COLORLength);
$COLORColStart = strpos($COLORString, "=") + 1;
$COLORColEnd = strpos($COLORString, "]");
$COLORColLength = $COLORColEnd - $COLORColStart;
$COLORCol = substr($COLORString, $COLORColStart, $COLORColLength);
$COLORTextStart = strpos($COLORString, "]") + 1;
$COLORTextEnd = strpos($COLORString, "[", $COLORTextStart);
$COLORTextLength = $COLORTextEnd - $COLORTextStart;
$COLORText = substr($COLORString, $COLORTextStart, $COLORTextLength);
$COLOR = "<SPAN STYLE=\"color: #" . $COLORCol . ";\">" . $COLORText . "</SPAN>";
$message = str_replace($COLORString, $COLOR, $message);
}
while (strpos($message,"[COLOR=") != FALSE); //End of COLOR
}
$message = str_replace("", "", $message); //SIZE
//if (strpos($message,"[SIZE=") != FALSE)
{
do
{
$SIZEStartPos = @strpos($message,"[SIZE=");
$SIZEEndPos = @strpos($message,"[/SIZE]") + 7;
$SIZELength = $SIZEEndPos -$SIZEStartPos;
$SIZEString = substr($message, $SIZEStartPos, $SIZELength);
$SIZEszStart = @strpos($SIZEString, "=") + 1;
$SIZEszEnd = @strpos($SIZEString, "]");
$SIZEszLength = $SIZEszEnd - $SIZEszStart;
$SIZEsz = substr($SIZEString, $SIZEszStart, $SIZEszLength);
$SIZETextStart = @strpos($SIZEString, "]") + 1;
$SIZETextEnd = @strpos($SIZEString, "[", $SIZETextStart);
$SIZETextLength = $SIZETextEnd - $SIZETextStart;
$SIZEText = substr($SIZEString, $SIZETextStart, $SIZETextLength);
$SIZE = "<SPAN STYLE=\"font-size: " . $SIZEsz . "px;\">" . $SIZEText . "</SPAN>";
$message = str_replace($SIZEString, $SIZE, $message);
}
while (strpos($message,"[SIZE=") != FALSE); //End of SIZE
}
$retVal = null;
$retVal = $message;
$message = null;
return $retVal;
}
?>
mfg Kinman
folgende Funktion funzt beim ersten mal einwandfrei aber sobald ich sie ein zweites mal aufrufe, funktioniert sie nicht mehr korrekt...
Sobald ich die IFs vor den schleifen aktivier (also eine while schleife aus der do while mache) funktionierts überalle, aber ineinandergeschachtelte bbcode funzen dann nimmer...
EDIT: Ups funzt nur dann nicht, wenn der BBCode ganz am Anfang steht...
<?php
function BBCode($message)
{
$message = trim($message); //Delete whitespaces in front and at the end of the message
$message = str_replace("\n", "<BR>", $message); //Convert breaks into <BR>
// $message = str_replace(" ", " ", $message); //Convert whitespaces to
$message = str_replace("\\\"", "\"", $message); //Delete the \ in front of a "
$message = str_replace("\'", "'", $message); //Delete the \ in front of a '
$message = str_replace("", "<B>", $message); //Bold text
$message = str_replace("", "</B>", $message); //Bold text
$message = str_replace("", "<B>", $message); //Bold text
$message = str_replace("", "</B>", $message); //Bold text
$message = str_replace("", "<U>", $message); //Underline
$message = str_replace("", "</U>", $message); //Underline
$message = str_replace("", "<U>", $message); //Underline
$message = str_replace("", "</U>", $message); //Underline
$message = str_replace("", "<I>", $message); //Italic text
$message = str_replace("", "</I>", $message); //Italic text
$message = str_replace("", "<I>", $message); //Italic text
$message = str_replace("", "</I>", $message); //Italic text
$message = str_replace("", "", $message); //Image
$message = str_replace("", "", $message); //Image
$message = str_replace("", "<IMG SRC=\"", $message); //Image
$message = str_replace("", "\">", $message); //Image
$message = str_replace("", "", $message); //Code
$message = str_replace("", "", $message); //Code
$message = str_replace("", "<SPAN STYLE=\"font-family: Courier New; font-size: 12px\">", $message); //Code
$message = str_replace("", "</SPAN>", $message); //Code
$message = str_replace("", "", $message); //URL
if (strpos($message,"[URL=") != FALSE)
{
do
{
$URLStartPos = strpos($message,"[URL=");
$URLEndPos = strpos($message,"[/URL]") + 6;
$URLLength = $URLEndPos -$URLStartPos;
$URLString = substr($message, $URLStartPos, $URLLength);
$URLLinkStart = strpos($URLString, "=") + 1;
$URLLinkEnd = strpos($URLString, "]");
$URLLinkLength = $URLLinkEnd - $URLLinkStart;
$URLLink = substr($URLString, $URLLinkStart, $URLLinkLength);
$URLTextStart = strpos($URLString, "]") + 1;
$URLTextEnd = strpos($URLString, "[", $URLTextStart);
$URLTextLength = $URLTextEnd - $URLTextStart;
$URLText = substr($URLString, $URLTextStart, $URLTextLength);
$URL = "<A HREF=\"" . $URLLink . "\" TARGET=\"_blank\" CLASS=text>" . $URLText . "</A>";
$message = str_replace($URLString, $URL, $message);
}
while (strpos($message,"[URL=") != FALSE); //End of URL
}
$message = str_replace("", "", $message); //COLOR
//if (strpos($message,"[COLOR=") != FALSE)
{
do
{
$COLORStartPos = strpos($message,"[COLOR=");
$COLOREndPos = strpos($message,"[/COLOR]") + 8;
$COLORLength = $COLOREndPos -$COLORStartPos;
$COLORString = substr($message, $COLORStartPos, $COLORLength);
$COLORColStart = strpos($COLORString, "=") + 1;
$COLORColEnd = strpos($COLORString, "]");
$COLORColLength = $COLORColEnd - $COLORColStart;
$COLORCol = substr($COLORString, $COLORColStart, $COLORColLength);
$COLORTextStart = strpos($COLORString, "]") + 1;
$COLORTextEnd = strpos($COLORString, "[", $COLORTextStart);
$COLORTextLength = $COLORTextEnd - $COLORTextStart;
$COLORText = substr($COLORString, $COLORTextStart, $COLORTextLength);
$COLOR = "<SPAN STYLE=\"color: #" . $COLORCol . ";\">" . $COLORText . "</SPAN>";
$message = str_replace($COLORString, $COLOR, $message);
}
while (strpos($message,"[COLOR=") != FALSE); //End of COLOR
}
$message = str_replace("", "", $message); //SIZE
//if (strpos($message,"[SIZE=") != FALSE)
{
do
{
$SIZEStartPos = @strpos($message,"[SIZE=");
$SIZEEndPos = @strpos($message,"[/SIZE]") + 7;
$SIZELength = $SIZEEndPos -$SIZEStartPos;
$SIZEString = substr($message, $SIZEStartPos, $SIZELength);
$SIZEszStart = @strpos($SIZEString, "=") + 1;
$SIZEszEnd = @strpos($SIZEString, "]");
$SIZEszLength = $SIZEszEnd - $SIZEszStart;
$SIZEsz = substr($SIZEString, $SIZEszStart, $SIZEszLength);
$SIZETextStart = @strpos($SIZEString, "]") + 1;
$SIZETextEnd = @strpos($SIZEString, "[", $SIZETextStart);
$SIZETextLength = $SIZETextEnd - $SIZETextStart;
$SIZEText = substr($SIZEString, $SIZETextStart, $SIZETextLength);
$SIZE = "<SPAN STYLE=\"font-size: " . $SIZEsz . "px;\">" . $SIZEText . "</SPAN>";
$message = str_replace($SIZEString, $SIZE, $message);
}
while (strpos($message,"[SIZE=") != FALSE); //End of SIZE
}
$retVal = null;
$retVal = $message;
$message = null;
return $retVal;
}
?>
mfg Kinman