CGollhardt
Mitglied
Ich habe folgende Dateien:
protect.inc.php
bbcode.function.php
Wenn ich nun einen Text aus zb. Golem.de herauskopiere, diesen in ein TextArea eingebe, der Post an die Datenbank geht, und später die bbcode() function sich diesen Text aus der Datenbank holt, habe ich das merkwürdige Ergebnis, dass da, wo einst Zeilenumbrüche waren, im Klartext (HTML Formatiert) als
\r\n in der Ausgabe stehen.
Hattet Ihr auch schonmal das Problem? Wisst Ihr woran das liegen könnte?
Vielen Dank für eure Antworten!
protect.inc.php
PHP:
<?php
//Gefahren in dem globalen Array Post entschärfen
foreach ($_POST as $var => $value) {
$value = trim ($value);
$value = htmlspecialchars ($value, ENT_QUOTES, 'UTF-8');
$value = strip_tags ($value);
$value = stripslashes ($value);
$value = mysql_real_escape_string ($value);
$_POST[$var] = $value;
}
//Gefahren in dem globalen Array Get entschärfen
foreach ($_GET as $var => $value) {
$value = trim ($value);
$value = htmlspecialchars ($value, ENT_QUOTES, 'UTF-8');
$value = strip_tags ($value);
$value = stripslashes ($value);
$value = mysql_real_escape_string ($value);
$_GET[$var] = $value;
}
//Gefahren in dem gloablen Array Cookie entschärfen
foreach ($_COOKIE as $var => $value) {
$value = trim ($value);
$value = htmlspecialchars ($value, ENT_QUOTES, 'UTF-8');
$value = strip_tags ($value);
$value = stripslashes ($value);
$value = mysql_real_escape_string ($value);
$_COOKIE[$var] = $value;
}
//Gloabalen Array Request Löschen, um Sicherheit zu erhöhen
unset($_REQUEST);
?>
bbcode.function.php
PHP:
<?php
function bbcode ($str) {
global $url;
$str = htmlentities($str, ENT_QUOTES, 'UTF-8');
$simple_search = array(
'/\[br\]/is',
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[s\](.*?)\[\/s\]/is',
'/\[url\=(.*?)\](.*?)\[\/url\]/is',
'/\[url\](.*?)\[\/url\]/is',
'/\[align\=(left|center|right|justify)\](.*?)\[\/align\]/is',
'/\[email\=(.*?)\](.*?)\[\/email\]/is',
'/\[email\](.*?)\[\/email\]/is',
'/\[youtube\](.*?)\[\/youtube\]/is',
'/http:\/\/(www\.)?youtube(\.[a-z]+){1,2}\/watch\?v=([a-z0-9_-]*)(&([a-z]+)=([a-z0-9_-])+)*?/is',
'/\[font\=(.*?)\](.*?)\[\/font\]/is',
'/\[size\=(1|2|3|4|5)\](.*?)\[\/size\]/is',
'/\[color\=(.*?)\](.*?)\[\/color\]/is',
'/\[quote\](.*?)\[\/quote\]/is',
'/\[quote\=(.*?)\](.*?)\[\/quote\]/is',
'/\[list\](.*?)\[\/list\]/is',
'/\[list\=(1|a)\](.*?)\[\/list\]/is',
'/\[\*\](.*?)\[\/\*\]/is',
'/\[p\](.*?)\[\/p\]/is',
'/<\/li>\s+<li>/is',
'/<\/li>\s+<\/ul>/is',
'/<\/li>\s+<\/ol>/is',
'/<ul>\s+<li>/is',
'/<ol type\="(1|a)">\s+<li>/is'
);
$simple_replace = array(
'<br />',
'<strong>$1</strong>',
'<em>$1</em>',
'<u>$1</u>',
'<strike>$1</strike>',
'<a href="' . $url['redirect'] . '&url=$1" rel="nofollow" target="_blank" title="$1">$2</a>',
'<a href="' . $url['redirect'] . '&url=$1" rel="nofollow" target="_blank" title="$1">$1</a>',
'<div style="text-align: $1;">$2</div>',
'<a href="mailto:$1">$2</a>',
'<a href="mailto:$1">$1</a>',
'<embed src="http://www.youtube.com/v/$1&hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="430" height="345" />',
'<embed src="http://www.youtube.com/v/$3&hd=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="430" height="345" />',
'<span style="font-family: $1;">$2</span>',
'<span style="font-size: $1em;">$2</span>',
'<span style="color: $1;">$2</span>',
'<blockquote style="margin-left:30px;"><div><i>Zitat:</i></div><div class="quote">$1</div></blockquote>',
'<blockquote style="margin-left:30px;"><div><i>Zitat von $1:</i></div><div class="quote">$2</div></blockquote>',
'<ul>$1</ul>',
'<ol type="$1">$2</ol>',
'<li>$1</li>',
'<p>$1</p>',
'</li><li>',
'</li></ul>',
'</li></ol>',
'<ul><li>',
'<ol type="$1"><li>'
);
$str = bbcode_code ($str);
$str = preg_replace_callback('/\[img\](.*?)\[\/img\]/is', 'GetImageHtmlCodeFromPregReplace', $str);
$ostring = $str;
$str = preg_replace ($simple_search, $simple_replace, $str);
while ($str != $ostring) {
$ostring = $str;
$str = preg_replace ($simple_search, $simple_replace, $str);
}
$str = bbcode_mail ($str);
$str = bbcode_NoRedirectToOwnUrl ($str);
$str = bbcode_addsmilies ($str);
$str = nl2br ($str);
$str = str_replace("&quot;", """, $str);
$str = str_replace("&amp;", "&", $str);
$str = str_replace("&#039;", "'", $str);
$str = str_replace("&lt;", "<", $str);
$str = str_replace("&gt;", ">", $str);
return $str;
}
function GetImageHtmlCodeFromPregReplace ($args) {
$newEncodedUri = 'grafik.php?url=' . urlencode($args[1]) . '&width=430';
return '<a href="' . $args[1] . '" target="_blank"><img src="' . $newEncodedUri . '" alt="" /></a>';
}
function bbcode_code ($str) {
if (preg_match_all ('/\[code\](.*?)\[\/code\]/is', $str, $codeVar) > 0) {
for ($i = 0; $i < count($codeVar[1]); $i++) {
$originalString = html_entity_decode($codeVar[1][$i], ENT_QUOTES, 'UTF-8');
$originalString = htmlspecialchars_decode($originalString, ENT_QUOTES);
$originalString = '<div style="margin-left:30px;"><i>Code:</i></div><div class="code">' . highlight_string($originalString, true) . '</div>';
$originalString = str_replace ("\n", '', $originalString);
$originalString = str_replace ("\r", '', $originalString);
$str = str_replace ('[code]' . $codeVar[1][$i] . '[/code]', $originalString, $str);
}
}
return $str;
}
function bbcode_mail ($str) {
if (preg_match_all ('/\"mailto(.*?)\"/is', $str, $mailVar) > 0) {
global $url;
for ($i = 0; $i < count($mailVar[1]); $i++) {
$emailAdresse = str_replace(':', '',$mailVar[1][$i]);
$maskierteMailAdresse = '';
for ($i = 0; $i < strlen ($emailAdresse); $i++) {
$maskierteMailAdresse.= '<i>' . substr($emailAdresse, $i, 1) . '</i>';
}
$maskierteMailAdresse = str_replace ('<i>@</i>', ' <span><u>„at“</u></span> ', $maskierteMailAdresse);
$maskierteMailAdresse = str_replace ('<i>.</i>', ' <span><u>„dot“</u></span> ', $maskierteMailAdresse);
$searchStr = array ('mailto:' . $emailAdresse, $emailAdresse);
$replaceStr = array ($url['email'] . '&encodedadress=' . base64_encode($emailAdresse), $maskierteMailAdresse);
$str = str_replace ($searchStr, $replaceStr, $str);
}
}
return $str;
}
function bbcode_addsmilies ($str) {
$smileys = ListData ('grafiken/smilies/','gif');
foreach ($smileys as $smiley) {
$smiley_code = ':' . strtok (basename ($smiley), '.') . ':';
$str = str_replace ($smiley_code, ' <img src="' . $smiley . '" alt="' . $smiley_code . '" />', $str);
}
return $str;
}
function bbcode_NoRedirectToOwnUrl ($str) {
global $url, $script;
$OwnURL = $url['redirect'] . '&url=' . $script['url'];
$OwnURLVariation = array ($OwnURL, str_replace ('www.','', $OwnURL), str_replace ('http://www.','', $OwnURL));
return str_replace ($OwnURLVariation, '', $str);
}
?>
Wenn ich nun einen Text aus zb. Golem.de herauskopiere, diesen in ein TextArea eingebe, der Post an die Datenbank geht, und später die bbcode() function sich diesen Text aus der Datenbank holt, habe ich das merkwürdige Ergebnis, dass da, wo einst Zeilenumbrüche waren, im Klartext (HTML Formatiert) als
\r\n in der Ausgabe stehen.
Hattet Ihr auch schonmal das Problem? Wisst Ihr woran das liegen könnte?
Vielen Dank für eure Antworten!