За последние 24 часа нас посетили 18088 программистов и 1589 роботов. Сейчас ищет 1081 программист ...

Проблема с кодировкой

Тема в разделе "PHP для новичков", создана пользователем soyansk, 13 дек 2007.

  1. soyansk

    soyansk Активный пользователь

    С нами с:
    13 дек 2007
    Сообщения:
    24
    Симпатии:
    0
    Помогите разобраться. Ниже приведен код. Проблема: не корректно отображается кириллица в пунктах меню .
    Что необходимо изменить или исправить?

    cjgmenu.php
    Код (Text):
    1. include("cjgmenuconfig.php");
    2.  
    3. function menuhere() {
    4. echo("<script>menuhere();</SCRIPT>\n"); }
    5.  
    6. function linea() { global $ln,$f;
    7. if(feof($f)) return(false);
    8. do { $l=fgets($f,4096); $l=trim($l); $ln++; } while(substr($l,0,2)=="//" || $l=="");
    9. return($l); }
    10.  
    11. function parse() { global $ln;
    12. $s="[ "; $c="";
    13. while($l=linea()) { if($l==")") { $s.="] "; return($s); }
    14. $a=split(",",$l,4);
    15. if(count($a)<4) die("Expected 4 comma-separated fields (line $ln)");
    16. if($a[3]!="(") $icon=htmlentities(trim($a[3]),ENT_QUOTES); else $icon="";
    17. $label=htmlentities($a[0],ENT_QUOTES);
    18. $url=htmlentities($a[1],ENT_QUOTES);
    19. $target=htmlentities($a[2],ENT_QUOTES);
    20. $s.=$c."['$label','$url','$target','$icon',0,'','',0,0,";
    21. if($a[3]=="(") $s.=parse()."] "; else $s.="''] "; $c=","; }
    22. die("Unexpected EOF in $def"); }
    23.  
    24. $f=fopen($def,"r") or die("Can't open $def");
    25. $ln=0;
    26. $l=linea($f) or die("Unexpected EOF in $def");
    27. if($l!="(") die("Format error in $def (line $ln): expected '('");
    28.  
    29. echo("<script>\n");
    30. echo("var showfoldericon=$showfoldericon;\n");
    31. echo("var showfileicon=$showfileicon;\n");
    32. echo("var shownodelines=$shownodelines;\n");
    33. echo("var showroot=$showroot;\n");
    34. echo("var folderimages='$folderimages';\n");
    35. echo("var foldericons='$foldericons';\n");
    36.  
    37. echo("var imgattrs=' width=$imgwidth height=$imgheight border=0';\n");
    38. echo("var imgroot='$imgroot';\n");
    39. echo("var imgfolderclose='$imgfolderclose';\n");
    40. echo("var imgfolderopen='$imgfolderopen';\n");
    41. echo("var imgplustop='$imgplustop';\n");
    42. echo("var imgplustopbot='$imgplustopbot';\n");
    43. echo("var imgplusmiddle='$imgplusmiddle';\n");
    44. echo("var imgplusbottom='$imgplusbottom';\n");
    45. echo("var imgminusmiddle='$imgminusmiddle';\n");
    46. echo("var imgminustop='$imgminustop';\n");
    47. echo("var imgminustopbot='$imgminustopbot';\n");
    48. echo("var imgminusbottom='$imgminusbottom';\n");
    49. echo("var imgjoinmiddle='$imgjoinmiddle';\n");
    50. echo("var imgjointop='$imgjointop';\n");
    51. echo("var imgjointopbot='$imgjointopbot';\n");
    52. echo("var imgjoinbottom='$imgjoinbottom';\n");
    53. echo("var imglinemiddle='$imglinemiddle';\n");
    54. echo("var imglinebottom='$imglinebottom';\n");
    55. echo("var imgfiledefault='$imgfiledefault';\n");
    56. echo("</SCRIPT>\n");
    57. echo("<LINK rel='STYLESHEET' type='text/css' href='cjgmenu.css'>\n");
    58. echo("<script language='JavaScript' src='cjgmenu.js'></SCRIPT>\n");
    59. echo("<script>\n");
    60. echo("var root=['','','','',0,'','m0',0,0,".parse()."];\n");
    61. echo("</SCRIPT>\n");
    62.  
    63. fclose($f);
    64.  
    65. ?>


    cjgmenuconfig.php

    Код (Text):
    1. <?php
    2. /*------------------------------------------------------------------------------
    3. CJG MENU v1.0 - Html Tree Menu Structure - Copyright (C) 2002 CARLOS GUERLLOY  
    4. cjgmenu@guerlloy.com
    5. guerlloy@hotmail.com
    6. carlos@weinstein.com.ar
    7. Buenos Aires, Argentina
    8. --------------------------------------------------------------------------------
    9. This program is free software; you can  redistribute it and/or  modify it  under
    10. the terms   of the   GNU General   Public License   as published   by the   Free
    11. Software Foundation; either  version 2   of the  License, or  (at  your  option)
    12. any  later version. This program  is  distributed in  the hope that  it  will be
    13. useful,  but  WITHOUT  ANY  WARRANTY;  without  even  the   implied  warranty of
    14. MERCHANTABILITY  or FITNESS  FOR A  PARTICULAR  PURPOSE.  See the  GNU   General
    15. Public License for   more details. You  should have received  a copy of  the GNU
    16. General Public License along  with this  program; if   not, write  to the   Free
    17. Software  Foundation, Inc.,  59 Temple Place,  Suite 330, Boston,  MA 02111-1307
    18. USA
    19. ------------------------------------------------------------------------------*/
    20.  
    21. $def="cjgmenu.def";            // Menu definition file
    22.  
    23. $showfoldericon=1;            // Show/Hide folder icons
    24. $showfileicon=1;            // Show/Hide file icons
    25. $shownodelines=1;            // Show/Hide lines and plus/minus icons
    26. $showroot=0;                // Show/Hide root icon
    27.  
    28. $imgwidth=19;                // Width for all icons and lines
    29. $imgheight=16;                // Height for all icons and lines
    30.  
    31. $folderimages="img";            // Location for images
    32. $foldericons="ico";            // Location for custom file icons
    33.  
    34. // All these icons must be located under $folderimages folder
    35. $imgroot="folderopen.gif";        // Icon for root folder
    36. $imgfolderclose="folderclose.gif";    // Icon for closed folder
    37. $imgfolderopen="folderopen.gif";    // Icon for opened folder
    38. $imgplustop="plustop.gif";        // Icon for top plus mark
    39. $imgplustopbot="plustopbot.gif";    // Icon for unique plus mark
    40. $imgplusmiddle="plusmiddle.gif";    // Icon for middle plus mark
    41. $imgplusbottom="plusbottom.gif";    // Icon for bottom plus mark
    42. $imgminustop="minustop.gif";        // Icon for top minus mark
    43. $imgminustopbot="minustopbot.gif";    // Icon for unique minus mark
    44. $imgminusmiddle="minusmiddle.gif";    // Icon for middle minus mark
    45. $imgminusbottom="minusbottom.gif";    // Icon for bottom minus mark
    46. $imgjointop="jointop.gif";        // Icon for top join line
    47. $imgjointopbot="jointopbot.gif";    // Icon for unique join line
    48. $imgjoinmiddle="joinmiddle.gif";    // Icon for middle join line
    49. $imgjoinbottom="joinbottom.gif";    // Icon for bottom join line
    50. $imglinemiddle="linemiddle.gif";    // Icon for line
    51. $imglinebottom="linebottom.gif";    // Icon for bottom line (space)
    52. $imgfiledefault="page.gif";        // Icon for files
    53.  
    54.  
    55.  
    56.  
    57. ?>


    cjgmenu.js

    Код (Text):
    1. /*------------------------------------------------------------------------------
    2. CJG MENU v1.0 - Html Tree Menu Structure - Copyright (C) 2002 CARLOS GUERLLOY  
    3. cjgmenu@guerlloy.com
    4. guerlloy@hotmail.com
    5. carlos@weinstein.com.ar
    6. Buenos Aires, Argentina
    7. --------------------------------------------------------------------------------
    8. This program is free software; you can  redistribute it and/or  modify it  under
    9. the terms   of the   GNU General   Public License   as published   by the   Free
    10. Software Foundation; either  version 2   of the  License, or  (at  your  option)
    11. any  later version. This program  is  distributed in  the hope that  it  will be
    12. useful,  but  WITHOUT  ANY  WARRANTY;  without  even  the   implied  warranty of
    13. MERCHANTABILITY  or FITNESS  FOR A  PARTICULAR  PURPOSE.  See the  GNU   General
    14. Public License for   more details. You  should have received  a copy of  the GNU
    15. General Public License along  with this  program; if   not, write  to the   Free
    16. Software  Foundation, Inc.,  59 Temple Place,  Suite 330, Boston,  MA 02111-1307
    17. USA
    18. ------------------------------------------------------------------------------*/
    19.  
    20. var VLABEL=0;
    21. var VHREF=1;
    22. var VTARGET=2;
    23. var VICON=3;
    24. var VOPEN=4;
    25. var VPARENT=5;
    26. var VNAME=6;
    27. var VPOS=7;
    28. var VHEIGHT=8;
    29. var VMENU=9;
    30.  
    31. var IROOT=0;
    32. var IFOLDER=1;
    33. var IPLUS=2;
    34. var IMINUS=3;
    35. var IJOIN=4;
    36. var ILINE=5;
    37. var IFILE=6;
    38. var ICLOSE=0;
    39. var IOPEN=1;
    40. var IMIDDLE=0;
    41. var IBOTTOM=1;
    42. var ITOP=2;
    43. var ITOPBOT=3;
    44.  
    45. var seqname=0;
    46. var selback='';
    47.  
    48. function menuhtml(sm,id) { var i,s,o,starget,shref,sfolder,sfile,splus,sjoin,stomenu;
    49. if(arguments.length<1) sm="root[VMENU]";
    50. if(arguments.length<2) id=0; seqname=id+1;
    51. var m=eval(sm);
    52. s="<TABLE class=tm id=m"+id+" border=0 cellspacing=0 cellpadding=0>\n";
    53. if(showfoldericon) sfolder='<IMG align=absmiddle src="'+menuimg(IFOLDER,ICLOSE)+'" '+imgattrs+'>'; else sfolder='';
    54. if(id==0 && showfoldericon && shownodelines && showroot) s+='<TR><TD><IMG src="'+menuimg(IROOT)+'" '+imgattrs+'>\n';
    55. for(i=0;i<m.length;i++) { o=m[i];
    56. o[VPOS]=IMIDDLE; if(i==m.length-1) o[VPOS]=IBOTTOM;
    57. if(id==0 && !showroot && shownodelines) { if(!i) o[VPOS]=ITOP; if(m.length==1) o[VPOS]=ITOPBOT; }
    58. if(o[VTARGET]!='') starget=' target="'+o[VTARGET]+'"'; else starget='';
    59. if(o[VHREF]!='') shref=' href="'+o[VHREF]+'"'; else shref=' href="#"';
    60. if(shownodelines)  splus='<IMG src="'+menuimg(IPLUS,o[VPOS])+'" '+imgattrs+'>'; else splus='';
    61. sjoin='<IMG src="'+menuimg(IJOIN,o[VPOS])+'" '+imgattrs+'>';
    62. if(o[VMENU]!='') {
    63. s+="<TR><TD><A onclick='menuanchor(this,\""+sm+"\","+i+");'>"+splus+"</A></TD><TD nowrap>"+sfolder+"<A id=t"+id+"_"+i+shref+starget+" onclick='menusel(this);menuopen(this,\""+sm+"\","+i+");'>"+o[VLABEL]+"</A></TD></TR>\n";
    64. } else {
    65. if(showfileicon) sfile='<IMG align=absmiddle src="'+menuimg(IFILE,o[VICON])+'" '+imgattrs+'>'; else sfile='';
    66. s+="<TR><TD>"+sjoin+"</TD><TD nowrap>"+sfile+"<A id=t"+id+"_"+i+shref+starget+" onclick='menusel(this);'>"+o[VLABEL]+"</A></TD></TR>\n";  
    67. } }
    68. s+="</TABLE>\n"; return(s); }
    69.  
    70. function menuanchor(este,sm,opt) { var m=eval(sm);
    71. if(m[opt][VOPEN]) menuclose(este,sm,opt); else menuopen(este,sm,opt); }
    72.  
    73. function menuopen(este,sm,opt) { var m=eval(sm); var n;
    74. if(m[opt][VOPEN]) return;
    75. var t0=este.parentElement.parentElement.children.tags('TD')[0];
    76. var t1=este.parentElement.parentElement.children.tags('TD')[1];
    77. if(shownodelines) t0.children.tags('A')[0].children.tags('IMG')[0].src=menuimg(IMINUS,m[opt][VPOS]);
    78. if(showfoldericon) t1.children.tags('IMG')[0].src=menuimg(IFOLDER,IOPEN);
    79. n=seqname++; t1.innerHTML+=menuhtml(sm+'['+opt+'][VMENU]',n);
    80. m[opt][VOPEN]=1; m[opt][VNAME]="m"+n;
    81. for(var i=0;i<m[opt][VMENU].length;i++) m[opt][VMENU][i][VPARENT]=m[opt];
    82. if(shownodelines) menubacktd(m[opt],0); }
    83.  
    84. function menuclose(este,sm,opt) { var m=eval(sm);
    85. var t0=este.parentElement.parentElement.children.tags('TD')[0];
    86. var t1=este.parentElement.parentElement.children.tags('TD')[1];
    87. t0.innerHTML=t0.innerHTML.match(/.*<\/A>/);
    88. if(shownodelines) t0.children.tags('A')[0].children.tags('IMG')[0].src=menuimg(IPLUS,m[opt][VPOS]);
    89. t1.innerHTML=t1.innerHTML.match(/.*<\/A>/);
    90. if(showfoldericon) t1.children.tags('IMG')[0].src=menuimg(IFOLDER,ICLOSE);
    91. if(shownodelines) menubacktd(m[opt],1); menuclosevar(m[opt]); }
    92.  
    93. function menuclosevar(o) { var i;
    94. if(o[VMENU]!="") { o[VNAME]=""; o[VOPEN]=0; o[VHEIGHT]=0;
    95. for(i=0;i<o[VMENU].length;i++) menuclosevar(o[VMENU][i]);  } }
    96.  
    97. function menuline(n,bottom) { var s,i;
    98. s='<TABLE class=tm border=0 cellspacing=0 cellpadding=0>';
    99. for(var i=0;i<n;i++) s+='<TR><TD><IMG src="'+menuimg(ILINE,bottom)+'" '+imgattrs+'></TD></TR>';
    100. s+='</TABLE>'; return(s); }
    101.    
    102. function menubacktd(o,neg) { var t0,s,e1;
    103. l=o[VMENU].length;
    104. if(neg) { l=-o[VHEIGHT]; o=o[VPARENT]; }
    105. while(o!='') { o[VHEIGHT]+=l;
    106. e1=eval(o[VNAME]);
    107. t0=e1.parentElement.parentElement.children.tags('TD')[0];
    108. s=t0.innerHTML.match(/<A.*<\/A>/); s+=menuline(o[VHEIGHT],o[VPOS]); t0.innerHTML=s;
    109. o=o[VPARENT]; } }
    110.  
    111. function menusel(t) {
    112. if(selback!='') { eval(selback).className=''; }
    113. selback=t.id; t.className='sel'; }
    114.  
    115. function menuimg(t,s) { var img,dir;
    116. dir=folderimages;
    117. switch(t) {
    118. case IROOT: img=imgroot; break;
    119. case IFOLDER: switch(s) {
    120.           case ICLOSE: img=imgfolderclose; break;
    121.           case IOPEN: img=imgfolderopen; break; } break;
    122. case IPLUS: switch(s) {          
    123.           case ITOP: img=imgplustop; break;
    124.           case ITOPBOT: img=imgplustopbot; break;
    125.           case IMIDDLE: img=imgplusmiddle; break;
    126.           case IBOTTOM: img=imgplusbottom; break; } break;
    127. case IMINUS: switch(s) {          
    128.           case ITOP: img=imgminustop; break;
    129.           case ITOPBOT: img=imgminustopbot; break;
    130.           case IMIDDLE: img=imgminusmiddle; break;
    131.           case IBOTTOM: img=imgminusbottom; break; } break;
    132. case IJOIN: switch(s) {          
    133.           case ITOP: img=imgjointop; break;
    134.           case ITOPBOT: img=imgjointopbot; break;
    135.           case IMIDDLE: img=imgjoinmiddle; break;
    136.           case IBOTTOM: img=imgjoinbottom; break; }
    137.           if(!shownodelines) img=imglinebottom; break;
    138. case ILINE: switch(s) {          
    139.           case IBOTTOM: case ITOPBOT: img=imglinebottom; break;
    140.           default: img=imglinemiddle; break; } break;
    141. case IFILE: if(s=='') img=imgfiledefault; else { dir=foldericons; img=s; } break;
    142. }
    143. return(dir+"/"+img); }
    144.  
    145. function menuexpand(r,i) { return(menuclick(r,i,false)); }
    146.  
    147. function menucollapse(r,i) { return(menuclick(r,i,true)); }
    148.  
    149. function menuclick(r,n,oc) { var m,qt,mh,o,i;
    150. if(r[VNAME]=='') return(false);
    151. mh=eval(r[VNAME]); m=r[VMENU];
    152. if(typeof(n)=='number') i=n; else { for(i=0;i<m.length;i++) if(n==m[i][VLABEL]) break; if(i==m.length) return(false); }
    153. qt=mh.children.tags('TBODY')[0].children.tags('TR'); o=m[i];
    154. if(o[VMENU]!='') { if(o[VOPEN]==oc) qt[i].children.tags('TD')[0].children.tags('A')[0].click(); } return(o); }    
    155.  
    156. function menuexpandall(r) { var m,i,qt,mh,o;
    157. if(arguments.length<1) { r=root; } mh=eval(r[VNAME]); m=r[VMENU];
    158. qt=mh.children.tags('TBODY')[0].children.tags('TR');
    159. for(i=0;i<m.length;i++) { o=m[i];
    160. if(o[VMENU]!='') { if(!o[VOPEN]) qt[i].children.tags('TD')[0].children.tags('A')[0].click();
    161. menuexpandall(o); } } }
    162.  
    163. function menucollapseall() { var i,qt,o,m;
    164. qt=m0.children.tags('TBODY')[0].children.tags('TR'); m=root[VMENU];
    165. for(i=0;i<m.length;i++) { o=m[i];
    166. if(o[VMENU]!='') { if(o[VOPEN]) qt[i].children.tags('TD')[0].children.tags('A')[0].click(); menuclosevar(o); } } }
    167.  
    168. function menuhere() { document.write(menuhtml()); }



    cjgmenu.def
    Код (Text):
    1. (
    2. Numbers,,,(
    3.     One,w.php?p=one.html,_blank,
    4.     )
    5. Letters,,,(
    6.     Alfa,w.php?p=alfa.html,_blank,
    7.     )
    8. Colors,,,(
    9.     Blue,w.php?p=blue.html,_blank,
    10.     Green,w.php?p=green.html,_blank,html.gif
    11.     Red,w.php?p=red.html,_blank,
    12.     Grayscales,,,(
    13.         Black,w.php?p=black.html,_blank,
    14.         Dark gray,w.php?p=darkgray.html,_blank,
    15.         Gray,w.php?p=gray.html,_blank,
    16.         Light gray,w.php?p=lightgray.html,_blank,
    17.         White,w.php?p=white.html,_blank,
    18.         Deeper,w.php?p=deeper.html,_blank,(
    19.             I'm,w.php?p=im.html,_blank,
    20.             Out of,w.php?p=outof.html,_blank,
    21.             Topics,w.php?p=topics.html,_blank,
    22.             )
    23.         )
    24.     Yellow,w.php?p=yellow.html,_blank,
    25.     )
    26. Months,,,(
    27.     January,w.php?p=january.html,_blank,
    28.     )
    29. Weekdays,,,(
    30.     Monday,w.php?p=monday.html,_blank,
    31.     )
    32. )
     
  2. host

    host Активный пользователь

    С нами с:
    20 июн 2007
    Сообщения:
    733
    Симпатии:
    3
    не осилил. Попробуйте отправить нужную кодировку используя header()