Op deze website gebruiken we cookies om content en advertenties te personaliseren, om functies voor social media te bieden en om ons websiteverkeer te analyseren. Ook delen we informatie over uw gebruik van onze site met onze partners voor social media, adverteren en analyse. Deze partners kunnen deze gegevens combineren met andere informatie die u aan ze heeft verstrekt of die ze hebben verzameld op basis van uw gebruik van hun services. Meer informatie.

Akkoord

Vraag & Antwoord

Webprogrammeren & scripting

database charactersets problemen

abraracourcix
3 antwoorden
  • Hallo,

    Zie mijn gastenboekje http://vanderburgt.eu/bezoekers/

    De database geeft aan dat de instelling utf-8 is. Dat geef ik ook steeds aan mijn webpagina's als encoding mee.
    In mijn gastenboek staan berichten die ik geïmporteerd heb uit een ouder gastenboek bij een "free webhost" en die bevatten een ë die niet goed worden weergegeven. Ik weet dat een ë in utf-8 eigenlijk ë zou moeten zijn, maar hoe bereik ik dat?

    Dit is de code:

    [code:1:8eb2bd201c]

    <?
    session_start();
    include "header.php";
    ?>

    <SCRIPT LANGUAGE="Javascript">
    //<!–
    // pop a windoid (Pictures)
    function popWin(url, w, h)
    {
    var madURL = url;
    var x, y, winStr;
    x=0; y=0;
    self.name="opener";
    winStr = "height="+h+",width="+w+",screenX="+x+",left="+x+",screenY="+y+",top="+y+",channelmode=0,dependent=0,directories=0,fullscreen=0,location=0,menubar=0,resizable=1,scrollbars=0,status=0,toolbar=0";
    lilBaby = window.open(madURL, "_blank", winStr);
    }
    //–> </script>

    <link rel='stylesheet' href='admin/style.css' type='text/css'>
    <?
    $numentries=15;
    include "admin/connect.php";
    print "<center>";
    print "<table class='maintable'>";
    print "<tr class='headline'><td></td>";
    print "<td valign='top' width='80%'>";
    print "<table border='0' width='100%'><tr class='headline'><td valign='top' width='75%'>";
    if(!isset($_GET['start']))
    {
    $start=0;
    }
    else
    {
    $start=$_GET['start'];
    }


    $order="SELECT * from gbook";
    $order2=mysql_query($order) or die(mysql_error());
    $d=0;
    $f=0;
    $g=1+$d/$numentries;


    $num=mysql_num_rows($order2);

    print "Page: ";
    $prev=$start-$numentries;
    $next=$start+$numentries;
    if($start>=$numentries)
    {
    print "<A href='index.php?start=$prev'><<</a>&nbsp;";
    }
    while($order3=mysql_fetch_array($order2))
    {

    if($f>=$start-3*$numentries&&$f<=$start+7*$numentries)
    {

    if($f%$numentries==0)
    {


    print "<A href='index.php?start=$d'>$g</a> ";

    }
    }
    $d=$d+1;
    $g=1+$d/$numentries;
    $f++;

    }

    if($start<=$num-$numentries)
    {
    print "<A href='index.php?start=$next'>>></a>&nbsp;";
    }



    print "</td>";
    print "<td valign='top' width='25%'>";
    print "<center><A href='addentry.php'>[Sign Guestbook]</center></a>";
    print "</td></tr></table>";

    print "</td>";

    $gbvar="Select * FROM gbook order by ID DESC LIMIT " . $start . ", $numentries"; /
    etrieve entries from sql
    $row=mysql_query($gbvar) or die(mysql_error());
    $formatcount=0; //color display counter

    while($gbvalues=mysql_fetch_array($row))
    {


    $gbvalues[comment]=htmlspecialchars($gbvalues[comment]);
    $gbvalues[name]=htmlspecialchars($gbvalues[name]);
    $gbvalues[country]=htmlspecialchars($gbvalues[country]);
    $gbvalues[comment]=BBCode($gbvalues[comment]);
    $gbvalues[comment]=smile($gbvalues[comment]);


    if ($formatcount%2==0)
    {


    print "<tr class='row1'><td valign='top' width='20%'>";
    print "<font size='2'>$gbvalues[realtime]<br>";
    print "<b><font size='3'>$gbvalues[name]</font></b><br>";
    print "<font size='2'>$gbvalues[country]</font><br><br>";
    if($gbvalues[homepage])
    {
    print "<A href='$gbvalues[homepage]'><img src='images/homepage.gif' border='0'></a> ";
    }
    if($gbvalues[mail])
    {
    print "<A href='mailto:$gbvalues[mail]'><img src='images/email.gif' border='0'></a><br>";
    }
    if($gbvalues[aim])
    {
    print "<A href=\"javascript:popWin('aim.php?ID=$gbvalues[ID]',400, 5)\"><img src='images/aim.gif' alt='$gbvalues[aim]' border='0'></a> ";
    }
    if($gbvalues[icq])
    {
    print "<A href=\"javascript:popWin('icq.php?ID=$gbvalues[ID]',400, 5)\"><img src='images/icq.gif' alt='$gbvalues[icq]' border='0'></a> ";
    }

    if($gbvalues[msn])
    {
    print "<A href=\"javascript:popWin('msn.php?ID=$gbvalues[ID]',400, 5)\"><img src='images/msn.gif' alt='$gbvalues[msn]' border='0'></a> ";
    }
    if($gbvalues[yim])
    {
    print "<A href=\"javascript:popWin('yim.php?ID=$gbvalues[ID]',400, 5)\"><img src='images/yim.gif' alt='$gbvalues[yim]' border='0'></a> ";
    }
    if(isset($_SESSION['username']))
    {
    print"<br>IP: $gbvalues[IP]";
    }
    print "</td>";
    print "<td valign='top' width='80%'>";
    print "<font color='#$fontcolor'>";
    $gbvalues[comment] = wordwrap( $gbvalues[comment], 19, "
    ", 1);
    print "$gbvalues[comment]";
    if(isset($_SESSION['username']))
    {
    print "<br><br><A href='admin/edit.php?ID=$gbvalues[ID]'>Edit</a>&nbsp;&nbsp;<A href='admin/delete.php?ID=$gbvalues[ID]'>Delete</a>";
    }
    print "</td></tr>";
    $formatcount++;
    }

    else
    {


    print "<tr class='row2'><td valign='top' width='20%'>";
    print "<font size='2'>$gbvalues[realtime]<br>";
    print "<b><font size='3'>$gbvalues[name]</font></b><br>";
    print "<font size='2'>$gbvalues[country]</font><br><br>";
    if($gbvalues[homepage])
    {
    print "<A href='$gbvalues[homepage]'><img src='images/homepage.gif' border='0'></a> ";
    }
    if($gbvalues[mail])
    {
    print "<A href='mailto:$gbvalues[mail]'><img src='images/email.gif' border='0'></a><br>";
    }
    if($gbvalues[aim])
    {
    print "<A href=\"javascript:popWin('aim.php?ID=$gbvalues[ID]',400, 5)\"><img src='images/aim.gif' alt='$gbvalues[aim]' border='0'></a> ";
    }
    if($gbvalues[icq])
    {
    print "<A href=\"javascript:popWin('icq.php?ID=$gbvalues[ID]',400, 5)\"><img src='images/icq.gif' alt='$gbvalues[icq]' border='0'></a> ";
    }

    if($gbvalues[msn])
    {
    print "<A href=\"javascript:popWin('msn.php?ID=$gbvalues[ID]',400, 5)\"><img src='images/msn.gif' alt='$gbvalues[msn]' border='0'></a> ";
    }
    if($gbvalues[yim])
    {
    print "<A href=\"javascript:popWin('yim.php?ID=$gbvalues[ID]',400, 5)\"><img src='images/yim.gif' alt='$gbvalues[yim]' border='0'></a> ";
    }
    if(isset($_SESSION['username']))
    {
    print"<br>IP: $gbvalues[IP]";
    }
    print "</td>";
    print "<td valign='top' width='80%'>";
    print "<font color='#$fontcolor'>";
    $gbvalues[comment] = wordwrap( $gbvalues[comment], 19, "
    ", 1);
    print "$gbvalues[comment]";
    if(isset($_SESSION['username']))
    {
    print "<br><br><A href='admin/edit.php?ID=$gbvalues[ID]'>Edit</a>&nbsp;&nbsp;<A href='admin/delete.php?ID=$gbvalues[ID]'>Delete</a>";
    }

    print "</td></tr>";
    $formatcount++;
    }

    }
    print "</table>";
    print "<br><center><font size='2' color='$fontcolor'>Powered by © <A href='http://www.chipmunk-scripts.com'>Chipmunk Guestbook</a></font></center>";

    ?>

    <? //BBCODE function
    //Local copy

    function BBCode($Text)
    {
    // Replace any html brackets with HTML Entities to prevent executing HTML or script
    // Don't use strip_tags here because it breaks [url] search by replacing & with amp


    // Convert new line chars to html <br /> tags
    $Text = nl2br($Text);

    // Set up the parameters for a URL search string
    $URLSearchString = " a-zA-Z0-9\:\/\-\?\&\.\=\_\~\#'";
    // Set up the parameters for a MAIL search string
    $MAILSearchString = $URLSearchString . " a-zA-Z0-9\.@";

    // Perform URL Search
    $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/", '<a href="$1" target="_blank">$1</a>', $Text);
    $Text = preg_replace("(\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[/url\])", '<a href="$1" target="_blank">$2</a>', $Text);
    $Text = preg_replace("/\[URL\]([$URLSearchString]*)\[\/URL\]/", '<a href="$1" target="_blank">$1</a>', $Text);
    $Text = preg_replace("(\[URL\=([$URLSearchString]*)\]([$URLSearchString]*)\[/URL\])", '<a href="$1" target="_blank">$2</a>', $Text);
    // Perform MAIL Search
    $Text = preg_replace("(\[mail\]([$MAILSearchString]*)\[/mail\])", '<a href="mailto:$1">$1</a>', $Text);
    $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.+?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $Text);

    // Check for bold text
    $Text = preg_replace("(\[b\](.+?)\[\/b])is",'<span class="bold">$1</span>',$Text);

    // Check for Italics text
    $Text = preg_replace("(\[i\](.+?)\[\/i\])is",'<span class="italics">$1</span>',$Text);

    // Check for Underline text
    $Text = preg_replace("(\[u\](.+?)\[\/u\])is",'<span class="underline">$1</span>',$Text);

    // Check for strike-through text
    $Text = preg_replace("(\[s\](.+?)\[\/s\])is",'<span class="strikethrough">$1</span>',$Text);

    // Check for over-line text
    $Text = preg_replace("(\[o\](.+?)\[\/o\])is",'<span class="overline">$1</span>',$Text);

    // Check for colored text
    $Text = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])is","<span style=\"color: $1\">$2</span>",$Text);

    // Check for sized text
    $Text = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])is","<span style=\"font-size: $1px\">$2</span>",$Text);

    // Check for list text
    $Text = preg_replace("/\[list\](.+?)\[\/list\]/is", '<ul class="listbullet">$1</ul>' ,$Text);
    $Text = preg_replace("/\[list=1\](.+?)\[\/list\]/is", '<ul class="listdecimal">$1</ul>' ,$Text);
    $Text = preg_replace("/\[list=i\](.+?)\[\/list\]/s", '<ul class="listlowerroman">$1</ul>' ,$Text);
    $Text = preg_replace("/\[list=I\](.+?)\[\/list\]/s", '<ul class="listupperroman">$1</ul>' ,$Text);
    $Text = preg_replace("/\[list=a\](.+?)\[\/list\]/s", '<ul class="listloweralpha">$1</ul>' ,$Text);
    $Text = preg_replace("/\[list=A\](.+?)\[\/list\]/s", '<ul class="listupperalpha">$1</ul>' ,$Text);
    $Text = str_replace("[*]", "<li>", $Text);


    // Check for font change text
    $Text = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<span style=\"font-family: $1;\">$2</span>",$Text);



    // Images
    // [img]pathtoimage[/img]
    $Text = preg_replace("/\[IMG\](.+?)\[\/IMG\]/", '<img src="$1">', $Text);
    $Text = preg_replace("/\[img\](.+?)\[\/img\]/", '<img src="$1">', $Text);
    // [img=widthxheight]image source[/img]
    $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.+?)\[\/img\]/", '<img src="$3" height="$2" width="$1">', $Text);

    return $Text;
    }
    ?>

    <? //function for smiley icons
    function smile($post)
    {
    $smilies=array(


    ':)' => "<img src='images/smile.gif' />",
    ':(' => "<img src='images/sad.gif' />",
    ':p' => "<img src='images/tongue.gif' />",
    ';)' => "<img src='images/wink.gif' />",
    ';smirk' => "<img src='images/smirk.gif' />",
    ':blush' =>"<img src='images/blush.gif' />",
    ':angry' =>"<img src='images/angry.gif' />",
    ':shocked'=> "<img src='images/shocked.gif' />",
    ':ninja'=>"<img src='images/ninja.gif' />",
    ':cool'=>"<img src='images/cool.gif' />",
    '(!)'=>"<img src='images/exclamation.gif' />",
    '(?)'=>"<img src='images/question.gif' />",
    '(heart)'=>"<img src='images/heart.gif' />",
    ':{blink}'=>"<img src='images/winking.gif'>",
    '{clover}'=>"<img src='images/clover.gif'>",
    ':[glasses]'=>"<img src='images/glasses.gif'>",
    ':[barf]'=>"<img src='images/barf.gif'>",
    ':[reallymad]'=>"<img src='images/mad.gif'>",
    ':[evil]'=>"<img src='images/melkor.gif'>"


    );

    $post=str_replace(array_keys($smilies), array_values($smilies), $post);
    return $post;
    }

    ?>

    <?
    include "footer.php";
    ?>
    [/code:1:8eb2bd201c]

    Alvast bedankt.

    Jos
  • Bestudeer dit commando eens: http://nl3.php.net/htmlspecialchars
  • Zit er in:

    $gbvalues[comment]=htmlspecialchars($gbvalues[comment]);
    $gbvalues[name]=htmlspecialchars($gbvalues[name]);
    $gbvalues[country]=htmlspecialchars($gbvalues[country]);
    $gbvalues[comment]=BBCode($gbvalues[comment]);
    $gbvalues[comment]=smile($gbvalues[comment]);

Beantwoord deze vraag

Dit is een gearchiveerde pagina. Antwoorden is niet meer mogelijk.