Announcement

Collapse
No announcement yet.

UTF-8 PHP File

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • UTF-8 PHP File

    Hello,

    Im having a block (written in php) that shows the lastest threads from my vB-forum on my index page.
    But sometimes members use charaters that doesnt show good in the browser. Its about the following (example): é, á, ü, etc......

    I know that UTF-8 encoding is the solution.

    But how do i put a line in php that carries for the utf-8 encoding of my php file.

    Content of the php file;

    PHP Code:
    <?php 
    // no direct access
    defined('_JEXEC') or die('Restricted access');
    $enum 0;
    if(
    is_array($items)){
     
    //Build items
     
    $row "";
     foreach (
    $items as $item){
      
    $style "class='sectiontableentry1'";
      if(
    $enum%== 0){
       
    $style "class='sectiontableentry2'";
      }
      if(
    strlen($item->title)>$title_len){
       
    $title substr($item->title0$title_len)."..";
      }else{
       
    $title $item->title;
      }
      
    $urlTopic   $jvbpixel->_bbURL."/showthread.php?t={$item->threadid}";
      
    $urlLastPost  $jvbpixel->_bbURL."/showthread.php?t={$item->threadid}&amp;goto=newpost";
      
    $urlForum   $jvbpixel->_bbURL."/forumdisplay.php?f={$item->fid}";
      
    $urlUser    $jvbpixel->_bbURL."/member.php?u={$item->postuserid}";
      
    $urlBoard   $jvbpixel->_bbURL;
      
    $row .= "
      <tr 
    {$style}>
        <td><a href='
    {$urlTopic}' title='{$item->title}'>{$title}</a><br/>In: <a href='{$urlForum}'>{$item->fname}</a></td>";
         if (
    $disp_author) {
          
    $row .= "
     <td><a href='
    {$urlUser}'>{$item->postusername}</a></td>";
      }
         if (
    $disp_view) {
          
    $row .= "
     <td style='text-align:center;'>
    {$item->views}</td>";
         }
         if (
    $disp_post) {
          
    $row .= "
     <td style='text-align:center;'>
    {$item->replycount}</td>";
         }
         if (
    $disp_date) {
          
    $row .= "
     <td><a href='
    {$urlLastPost}' title='get last comment..'>".date('d M Y'$item->lastpost )."</a><br/>by <b><i>{$item->lastposter}</i></b></td>";
         }
       
    $row .=
      
    "</tr>";
         
    $enum++;
        }
        
    //Display table
     
    if($enum>0){
      
    $content "
    <table width='100%' border='0' cellpadding='2' cellspacing='1' style='border: solid 0px;'>
      <tr>
     
    "
    ;
      if (
    $disp_author) {
       
    $content .= "
        <td class='sectiontableheader'><b>"
    .JText::_('AUTHOR')."</b></td>";
      }
      if (
    $disp_view) {
       
    $content .= "
     <td class='sectiontableheader'><b>"
    .JText::_('VIEWS')."</b></td>";
      }
      if (
    $disp_post) {
       
    $content .= "
     <td class='sectiontableheader'><b>"
    .JText::_('POSTS')."</b></td>";
      }
      if (
    $disp_date) {
       
    $content .= "
     <td class='sectiontableheader' nowrap=nowrap><b>"
    .JText::_('LAST POST')."</b></td>";
      }
      
    $content .="
      </tr>
    {$row}
      <tr><td colspan='5'>&nbsp;</td></tr>
    </table>"
    ;
     }
    }
    ?>

  • #2
    Is there nobody who want to help me with this issue.

    How can i make characters like; á é ü ä etc..... readable by inserting a utf-8 line into a php file.
    Where should i put this line? And how should it be?

    Comment


    • #3
      Don't know myself, have you checked the php utf encode and decode pages?
      Lats...

      Comment


      • #4
        You can create php files using Unicode UTF-8 encoding, however, you must note two things:
        1) You will need a text editor capable of editing files in different encodings (duh). On Windows, I used to use EmEditor, on Mac I'm currently using Smultron and Espresso.
        2) You _MUST_ make sure that BOM is NOT enabled. PHP 5 does not know what to do with the BOM, so it will spit those three bytes out to the browser before doing any of the scripting work (and hence break a lot of functionalities such as cookie and http header).
        Best Regards,
        Andy Huang

        Comment

        widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
        Working...
        X