Hey Community,
ich habe derzeitig ein -sich noch in den Kinderschuhen befindliches- Projekt.
Als nen Kumpel sich das angeschaut hat, hatte er erstmal wegen der Validierung gemeckert und meinte das ich statt ISO-iwas UTF-8 verwenden soll (halt weil dann auch zb japanisch angezeigt werden kann).
Nun tritt in meiner Kommentierfunktion aber leider ein Fehler auf:
Die Umlaute werden vom script normalerweise in die entsprechende HTML-Lautschrift umgewandelt. Mit der ISO codierung hat das alles wunderbar geklappt, aber nun wird mir bei der direkten Umwandlung statt “äöü” -> "äöü " angezeigt und bei bereits eingetragenen Dingen (die wohl nicht umgewandelt wurden) halt das gewöhnliche “?” (womit ich auch kein Problem hab).
Nun meine Frage: Wie sag ich PHP, dass es die Buchstaben richtig umwandelt und mir nicht irgendwelche Zeichen auswirft, die nicht funktionieren?
Hier mal der header samt comments.php (das ist die schreibende datei)
[code]<?php
ob_start();
session_start();
$session_id = session_id();
error_reporting(E_ALL);
header(“Content-Type: text/html; charset=UTF-8”);
ob_end_flush();
?>
[code]<?php
//Comments
include("…/include/header.inc.php");
include("…/include/config.inc.php");
/* ERROR REPORTING */
ini_set(‘display_errors’, 0);
echo ‘’;
echo ‘
//------------------------------------------------------------------------------------------------------//
//Zeit und Datum bestimmen
$Current_time = date(“H:i:s”);
$Current_weekday = date(“w”);
$Current_day = date(“j”);
$Current_month = date(“n”);
$Current_year = date(“Y”);
//------------------------------------------------------------------------------------------------------//
//Auslesen der News
$verbindung = mysql_connect($server, $benutzer, $passwort) or die(mysql_error());
mysql_select_db(“blog”) or die(mysql_error());
$abfrage = “SELECT Language, Title, Link FROM $news_table WHERE New LIKE ‘1’ AND Language = ‘English’”;
$ergebnis = mysql_query($abfrage) or die(mysql_error());
while($row = mysql_fetch_object($ergebnis))
{
$language_news = $row->Language;
$title_news = $row->Title;
$link_news = $row->Link;
}
//------------------------------------------------------------------------------------------------------//
//Ausgabe der Zeit, des Datums und der der News
echo “
echo "Server time: “.$Current_time.”; “.$Tage[$Current_weekday].” the ".$Current_day;
if($Current_day == 1)
{
echo "st ";
}elseif($Current_day == 21)
{
echo "st ";
}elseif($Current_day == 31)
{
echo "st ";
}elseif($Current_day == 2)
{
echo "nd ";
}elseif($Current_day == 22)
{
echo "nd ";
}elseif($Current_day == 3)
{
echo "rd ";
}elseif($Current_day == 23)
{
echo "rd ";
}else{
echo "th “;
}
echo $Monate[$Current_month].”, ".$Current_year;
echo “
//------------------------------------------------------------------------------------------------------//
//Auslesen des Verzeichnisses
$seite = $_SERVER[“PHP_SELF”];
//Definitionen
$datum = $Current_day.".".$Current_month.".".$Current_year;
$zeit = $Current_time."; ".$datum;
//Auslesen welche Blogs verfügbar sind
$blognames = array();
$abfrage3 = “SELECT Blogname FROM user”;
$ergebnis3 = mysql_query($abfrage3) or die(mysql_error());
while($blogs = mysql_fetch_object($ergebnis3))
{
$blognames[] = $blogs->Blogname;
}
//------------------------------------------------------------------------------------------------------//
//Welchen Blogbeitrag sollen wir laden?
$blogbeitrag = $_GET[“blog”];
$ip = $_SERVER[“REMOTE_ADDR”];
$blog_1 = “SELECT * FROM blog WHERE BlogID LIKE ‘$blogbeitrag’”;
$blog_2 = mysql_query($blog_1) or die(mysql_error());
while($bloginfo = mysql_fetch_object($blog_2))
{
$blog = $bloginfo->BlogID;
$user = $bloginfo->User;
$style = $bloginfo->Style;
}
echo ‘
if($style == 1)
{
$style_links = “blog_left_1”;
$style_rechts = “blog_right_1”;
$style_bild = “blog_image_1”;
$style_image = “style_1.png”;
$background = “background_1.png”;
}else{
echo “
”;
echo “
echo “The Style you chose is not avabile - Sorry. ;/”;
echo “
}
echo “
echo “So you want to make a comment but you are confused, or even have Questions about some parts??”;
echo “This is the right place to look, because we’ll try to answer them all!”;
echo “
”;
echo “I am just a guest, why do you need my Mail just as why do you save my IP?”;
echo “
”;
echo “You have the right to ask! We do need your e-Mail adress, in order to be able to contact you. Why you ask?”;
echo “For the chase, that something happens concerning your Comment for example! The reason could be: Warez Links.”;
echo “
”;
echo “You may wonder now, for what we save your IP. So the example above brings us to your IP.”;
echo “We save it for safety reasons. With saving your IP, we will be able to locate you, if you did something bad or illegal.”;
echo “Don’t worry!: We will not spam your Mail with any E-Mails, we will not contact you if not necessary. We also will keep your IP secret, we won’t tell it anybody!”;
echo “
”;
echo “I am a member, do you save my IP either?”;
echo “No, not when you are commenting. But please keep in mind: With every login we save it!”;
echo “
”;
echo “Can I edit my comment later??”;
echo “
”;
echo “No, you may now edit it if you made up your mind, but you cannot edit it later.”;
echo “
”;
echo “But I don’t want my comment to be diplayed anymore!”;
echo “
”;
echo “That’s another good reason why you should use your correct E-Mail adress. You can simply contact us via E-Mail and request a deletion of your comment. (The link to the belonging article just as the message and your used E-Mail adress is needed)”;
echo “
”;
echo “Why do I see the Blogarticle while the correction?”;
echo “
”;
echo "Because we thougt that it might be useful, since you might want to check something of the blog in your answers

echo “
”;
echo “Notice:”;
echo “
”;
echo “Please keep in mind, that we do not allow any Warez links. Posting things that are against German or your countrys laws are forbidden!”;
echo “We are able to ban your IP and will do so!”;
echo “
”;
echo “Are you having further Questions? Feel free to ask us on our Forum or via E-Mail! :)”;
echo “
echo “
$user = “SELECT User FROM blog”;
$user_read = mysql_query($user) or die(mysql_error());
while($read3 = mysql_fetch_object($user_read))
{
$username = $read3->User;
}
//Let user check the Comment again
//Definieren
$writter = $_POST[‘writter’];
$mail = $_POST[‘mail’];
$entry = $_POST[‘comment’];
$entry2 = $entry;
$entry2 = htmlentities($entry2);
$entry2 = str_replace("\n", “
”, $entry2);
$entry2 = str_replace("’", “’”, $entry2);
$entry2 = eregi_replace(“www.”, “http://www.”, $entry2);
$entry2 = eregi_replace(“http://http://”, “http://”, $entry2);
$entry2 = eregi_replace("[url]([^[]+)[/url]", “<a href=”\1" target="_blank">\1", $entry2);
$entry2 = eregi_replace("[url="([^"]+)"]([^[]+)[/url]","<a href="\1" target="_blank">\1",$entry2);
$entry2 = eregi_replace("[img]([^[]+)[/img]", “<img src=”\1" alt=“External Source”>", $entry2);
$entry2 = preg_replace(’#[b](.)[/b]#isU’, “$1”, $entry2);
$entry2 = preg_replace(’#[i](.)[/i]#isU’, “$1”, $entry2);
$entry2 = preg_replace(’#[u](.*)[/u]#isU’, “$1”, $entry2);
$entry2 = str_replace(":1st:", “<img src='http://”.$website_root."/images/smilies/1st.gif’ alt=‘1st’>", $entry2);
$entry2 = str_replace(":10on10:", “<img src='http://”.$website_root."/images/smilies/10on10.gif’ alt=‘10on10’>", $entry2);
$entry2 = str_replace(":bday:", “<img src='http://”.$website_root."/images/smilies/bday.gif’ alt=‘Happy Birthday’>", $entry2);
$entry2 = str_replace("", “<img src='http://”.$website_root."/images/smilies/bow.gif’ alt=‘bows’>", $entry2);
$entry2 = str_replace("", “<img src='http://”.$website_root."/images/smilies/cry.gif’ alt=‘crying’>", $entry2);
$entry2 = str_replace(":dont:", “<img src='http://”.$website_root."/images/smilies/dont.gif’ alt=‘do not’>", $entry2);
$entry2 = str_replace("", “<img src='http://”.$website_root."/images/smilies/grin.gif’ alt=‘grin’>", $entry2);
$entry2 = str_replace(“O_o”, “<img src='http://”.$website_root."/images/smilies/hypno.gif’ alt=‘O_o’>", $entry2);
$entry2 = str_replace(":lol:", “<img src='http://”.$website_root."/images/smilies/lol.gif’ alt=‘lol’>", $entry2);
$entry2 = str_replace(":shy:", “<img src='http://”.$website_root."/images/smilies/shy.gif’ alt=‘shy’>", $entry2);
$ip = $_POST['ip'];
$ipshow = $_POST['ipshow'];
$blogname = $_POST['blogname'];
$step = $_POST['step'];
$zahl1 = rand(1,100);
$zahl2 = rand(1,50);
if($zahl1 >50)
{
$zeichen = "-";
$captcha = $zahl1 - $zahl2;
}else{
$zeichen = "+";
$captcha = $zahl1 + $zahl2;
}
if(!isset($step))
{
echo “
echo “Error! Sorry, but directly visiting this page cannot help you!”;
echo “
”;
echo “Please go back to the site you came from and try to use the comment function under the blog article - Thank you!”;
echo “
}elseif($step == “2”)
{
if($ipshow == “1”)
{
echo “Your IP is “.$ip.”. We will not use it, but save it for safety reasons (anti-spam e.g.).”;
echo “
”;
}else{}
echo “You wrote:”;
echo “
”;
echo $entry2;
echo “
”;
echo “Are there any mistakes?? You now have the possibility to correct them:”;
echo “
”;
$letwrite = $_POST["letwrite"];
if($letwrite == 1)
{
$read = "";
}else{
$letwrite = "0";
$read = " readonly=\"readonly\"";
}
echo '<form action="http://'.$website_root.'/blog-extra/comment.php?blog='.$blogbeitrag.'" method="post">
<br />
<b>Name:</b> <input type="text" name="writter" value="'.$writter.'" readonly="readonly"><br />
<b>Your E-Mail:</b> <input type="text" name="mail" value="'.$mail.'"'.$read.'> (Won\'t appear!)<br />
<br /><b>Your Comment:</b><br />
<textarea name="comment" rows="4" cols="56" wrap="VIRTUAL">'.$entry.'</textarea>
<input type="hidden" name="ip" value="'.$ip.'">
<input type="hidden" name="ipshow" value="'.$ipshow.'">
<input type="hidden" name="blogname" value="'.$blogname.'">
<input type="hidden" name="step" value="2">
<br /><br /><b>If there aren\'t any mistakes to correct: Ignore this formular and croll further down, please</b>
<br /><br />
<input type="Submit" value="Next Step">
<input type="Reset" value="Reset changes">
</form>';
echo "<br /><br />";
echo "Your comment is without mistakes? Enter the Captcha and click on \"Post it!\"";
echo "<br /><br />";
echo "What makes ".$zahl1." ".$zeichen." ".$zahl2." ?";
echo " ";
echo '<form action="comment.php?blog='.$blogbeitrag.'" method="post">
<input type="text" name="captcha" size="5">
<input type="hidden" name="captcha_check" value="'.$captcha.'">
<input type="hidden" name="writter" value="'.$writter.'">
<input type="hidden" name="mail" value="'.$mail.'">
<input type="hidden" name="comment" value="'.$entry.'">
<input type="hidden" name="ip" value="'.$ip.'">
<input type="hidden" name="ipshow" value="'.$ipshow.'">
<input type="hidden" name="blogname" value="'.$blogname.'">
<input type="hidden" name="step" value="3">
<input type="submit" value="Post it!">
</form>';
}elseif($step == “3”)
{
//Definieren (again)
$captcha = $_POST[‘captcha’];
$captcha_check = $_POST[‘captcha_check’];
$written = $Current_day.".".$Current_month.".".$Current_year.", ".$Current_time;
if($captcha != $captcha_check)
{
echo "<div id='error_light'>";
echo "You entered a wrong Captcha code! Please try again.";
echo '<form action="comment.php?blog='.$blogbeitrag.'" method="post">
<input type="hidden" name="writter" value="'.$writter.'">
<input type="hidden" name="mail" value="'.$mail.'">
<input type="hidden" name="comment" value="'.$entry.'">
<input type="hidden" name="ip" value="'.$ip.'">
<input type="hidden" name="ipshow" value="'.$ipshow.'">
<input type="hidden" name="blogname" value="'.$blogname.'">
<input type="hidden" name="step" value="2">
<input type="submit" value="Back">
</form>';
echo "</div>";
}elseif($mail == "")
{
echo "<div id='error_light'>";
echo "Please enter your E-Mail adress!";
echo '<form action="comment.php?blog='.$blogbeitrag.'" method="post">
<input type="hidden" name="writter" value="'.$writter.'">
<input type="hidden" name="mail" value="'.$mail.'">
<input type="hidden" name="comment" value="'.$entry.'">
<input type="hidden" name="ip" value="'.$ip.'">
<input type="hidden" name="ipshow" value="'.$ipshow.'">
<input type="hidden" name="blogname" value="'.$blogname.'">
<input type="hidden" name="step" value="2">
<input type="hidden" name="letwrite" value="1">
<input type="submit" value="Back">
</form>';
echo "</div>";
}else{
if($ipshow == 2)
{
$ip = $writter;
}elseif($ipshow == 1)
{
$ip = $ip;
}else{}
//Edit entry
$entry = htmlentities($entry);
$entry = str_replace("\n", “
”, $entry);
$entry = str_replace("’", “’”, $entry);
$entry = eregi_replace(“www.”, “http://www.”, $entry);
$entry = eregi_replace(“http://http://”, “http://”, $entry);
$entry = eregi_replace("[url]([^[]+)[/url]", “<a href=”\1" target="_blank">\1", $entry);
$entry = eregi_replace("[url="([^"]+)"]([^[]+)[/url]","<a href="\1" target="_blank">\1",$entry);
$entry = eregi_replace("[img]([^[]+)[/img]", “<img src=”\1" alt=“External Source”>", $entry);
$entry = preg_replace(’#[b](.)[/b]#isU’, “$1”, $entry);
$entry = preg_replace(’#[i](.)[/i]#isU’, “$1”, $entry);
$entry = preg_replace(’#[u](.*)[/u]#isU’, “$1”, $entry);
$entry = str_replace(":1st:", “”, $entry);
$entry = str_replace(":10on10:", “”, $entry);
$entry = str_replace(":bday:", “”, $entry);
$entry = str_replace("", “
”, $entry);
$entry = str_replace("", “
”, $entry);
$entry = str_replace(":dont:", “”, $entry);
$entry = str_replace("", “
”, $entry);
$entry = str_replace(“O_o”, “”, $entry);
$entry = str_replace(":lol:", “”, $entry);
$entry = str_replace(":shy:", “”, $entry);
$comment = "INSERT INTO comments
(BlogID, User, Entry, Written, Mail, IP)
VALUES
('$blogbeitrag', '$writter', '$entry', '$written', '$mail', '$ip')";
$comment_add = mysql_query($comment) or die(mysql_error());
$comment_check = "SELECT * FROM blog WHERE BlogID LIKE '$blogbeitrag'";
$comment_count = mysql_query($comment_check) or die(mysql_error());
while($count = mysql_fetch_object($comment_count))
{
$comment_numb = $count->Comments;
}
$comment_numb_new = $comment_numb + “1”;
$change = "UPDATE blog Set
Comments = '$comment_numb_new'
WHERE BlogID = '$blogbeitrag'";
$update_change = mysql_query($change) or die(mysql_error());
echo "Your comment has been added.";
echo "<br />";
echo "<a href='http://".$website_root."/blog-extra/?article=".$blogbeitrag."'>Go back to visitted Blog article...</a>";
}
}else{}
echo "<br /><br />";
echo '<hr size="1,5" noshade>';
echo "<br /><br />";
//Blogentries
$entries = “SELECT * FROM blog WHERE BlogID LIKE ‘$blogbeitrag’”;
$entries_read = mysql_query($entries) or die(mysql_error());
while($read = mysql_fetch_object($entries_read))
{
$blogtitle = $read->Title;
echo "<b>".$read->Title."</b>";
echo "<br />";
echo "<i>Written by ".$read->User."; ".$read->Written."</i>";
echo "<br /><br />";
echo $read->Entry;
}
echo “
echo “
echo “
echo “
include("…/include/footer.inc.php");
echo ‘
echo ‘
?>
[/code]Für die, die sich das ganze Live anschauen wollen: http://mrgserver.ath.cx/blog/blog-extra/?article=5