ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingรบกวนถาม PHP, XML กับการแสดงข้อมูลภาษาไทยครับ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: รบกวนถาม PHP, XML กับการแสดงข้อมูลภาษาไทยครับ  (อ่าน 8193 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
nheuoi
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 6



ดูรายละเอียด
« เมื่อ: 07 มีนาคม 2010, 20:57:31 »

**ถ้าตั้งผิดหมวด ขออภัยไว้ล่วงหน้าด้วยนะครับ** wanwan031

ผมต้องการให้ xml แสดงผลและดึงข้อมูลเป็นภาษาไทยให้ได้ครับ แต่ติดปัญหาดังนี้
เท่าที่ผมหาดูจากกระทู้เก่าและกระทู้ของเวปอื่นๆ เห็นมีบอกว่านอกจาก encoding="utf-8" แล้ว ให้ save file เป็น utf-8 ด้วย แต่ทำยังไงก็ติด error อยู่ดี โดย code ไฟล์ที่ผมได้มาเป็นดังนี้

อ้างถึง
<?php
....
    header("Content-type: text/xml");
    echo "<?xml version='1.0' encoding='utf-8'?>";
    echo "<!-- generated by Visuwords(TM) xml.php ... visuwords.com -->";
    echo "<!-- (c) 2007 dunnbypaul.net -->";
    echo "<{$this->roottag}>";
...
?>

ซึ่ง encode ไฟล์ไว้เป็น ANSI ตอนดึงข้อมูล eng ก็ปกติดี แต่พอเปลี่ยนเป็นค่าตัวแปลไทยแล้วมันได้ error แบบนี้
อ้างถึง
The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
An invalid character was found in text content. Error processing resource 'http://localhost/visuwords/v2.0/lex.php?find= คำ'...

เลยลองทำตามกระทู้เก่าที่เคยบอกไว้ว่า ให้ save as ไฟล์เป็น UTF-8 กลายเป็นว่าผมได้ error แบบนี้แทน Shocked

อ้างถึง
The XML page cannot be displayed
Cannot view XML input using style sheet. Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
Invalid at the top level of the document. Error processing resource 'http://localhost/visuwords/v2.0/lex.php?find= กา'. Lin...

<?xml version='1.0' encoding='utf-8'?><!-- generated by Visuwords(TM) xml.php ... visuwords.com --><!-- (c)...

กลายเป็นว่า eng ก็ไม่ได้ ไทยก็ไม่ได้  Shocked เลยอยากถามพี่ๆครับว่า มันไปผิดตรงไหนครับ และแก้ยังไงดี
ขอบคุณล่วงหน้าครับ wanwan017
บันทึกการเข้า
ohmohm
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 170
ออฟไลน์ ออฟไลน์

กระทู้: 3,099



ดูรายละเอียด เว็บไซต์
« ตอบ #1 เมื่อ: 08 มีนาคม 2010, 22:51:59 »

save as UTF-8 without BOM ด้วยนะครับ http://www.thaiseoboard.com/index.php?topic=73791.0
แล้วถ้าเราใช้ Content-type: application/xml แทน จะมีความหมายต่างกันไหม
บันทึกการเข้า
g-ji
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 231
ออฟไลน์ ออฟไลน์

กระทู้: 3,254



ดูรายละเอียด เว็บไซต์
« ตอบ #2 เมื่อ: 08 มีนาคม 2010, 23:21:05 »

โครงสร้างมันอาจจะผิดนะ

โครงสร้าง XML ที่ถูกต้อง

โค๊ด:
<?xml version="1.0" encoding="UTF-8"?>
   
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://g-ji.com/manga_updates.xml" type="application/rss+xml" />
    <channel>
<title>G-ji Blog Manga</title>
<link>http://g-ji.com</link>
<description>G-ji Blog Latest Manga Updates</description>
<language>en-us</language>

<copyright>2010 Copyright G-ji Blog</copyright>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<managingEditor>the1ark1@hotmail.com</managingEditor>
<webMaster>the1ark1@hotmail.com</webMaster>
   
<image>
<url>http://g-ji.com/wp-content/themes/G_theme/images/g-ji-logo_feed.png</url>

<title>G-ji Blog Latest Manga Updates</title>
<link>http://g-ji.com</link>
<description>Feed provided by G-ji Blog. Click to visit.</description>
</image>
<item>
<title>Neue Green-chapter 02</title>
<description>Neue Green chapter 02 add on 04-Mar-10 : 14:04 pm</description>

<link>http://g-ji.com/read-manga/neue-green/chapter-02/1</link>
<guid>http://g-ji.com/read-manga/neue-green/chapter-02/1</guid>
<pubDate>04-Mar-10</pubDate>
</item>
</channel>
</rss>

อันนี้เจนเองด้วย php แต่ว่า ค่าวันที่แสดงผลไม่ถูกต้อง กำลังแก้อยู่  Tongue

<pubDate>04-Mar-10</pubDate>

จริงๆ มันต้องเป็น

<pubDate>Wed, 03 Mar 2010 05:07:09 +0000</pubDate>

ถึงจะถูกต้องตามหลัก XML

<image> ตรงนี้คือ โลโก้ เว็บ ใน feed !
โค๊ด:
	
<image>
<url>http://g-ji.com/wp-content/themes/G_theme/images/g-ji-logo_feed.png</url>

<title>G-ji Blog Latest Manga Updates</title>
<link>http://g-ji.com</link>
<description>Feed provided by G-ji Blog. Click to visit.</description>
</image>

ลองดู โครงสร้าง xml อีกทีเน้อ

ถ้าจะให้ดี หา RSS generator มาใช้เลยดีกว่า มีแจกเพียบเลย เราก็โหลดมาตัวนึง กำลังจะลองใช้
บันทึกการเข้า

@@@
Administrator
สมุนแก๊งเสียว
*

พลังน้ำใจ: 33
ออฟไลน์ ออฟไลน์

กระทู้: 634



ดูรายละเอียด เว็บไซต์
« ตอบ #3 เมื่อ: 09 มีนาคม 2010, 17:27:14 »

ต้องขอไฟลืมาดูด้วยละมั่งจ๊ะ  wanwan023
บันทึกการเข้า

รับซื้อเว็บ 100uip ต่อวันขึ้นไป EA Forex
nheuoi
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 6



ดูรายละเอียด
« ตอบ #4 เมื่อ: 16 มีนาคม 2010, 21:53:13 »

ขอบคุณทุกคำตอบครับ แต่ก็ยังไม่ออกอ่ะ  wanwan031

ผมลองใช้ Editplus แล้วไปเซ็ทให้ UTF-8 Signature เป็น Always remove signature แล้ว หลังจากนั้นผมเอาไฟล์ php ทุกไฟล์ Save as.. ทับใหม่อีกที แล้วลองรันอีกครั้ง คราวนี้ Eng ออก แต่ Thai ก็ยัง error น่ะครับ

Eng
โค๊ด:
<?xml version="1.0" encoding="utf-8" ?> 
- <!--  generated by Visuwords(TM) xml.php ... visuwords.com
  -->
- <!--  (c) 2007 dunnbypaul.net
  -->
- <lex>
- <lemma>
  <identity>word</identity>
- <associations>
- <node index="1">
  <type>-</type>
  <link>1:06286395</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>00</lex_id>
  <head_word />
  <head_id />
  <synset_offset>06286395</synset_offset>
  <sense_number>1</sense_number>
  <tag_cnt>117</tag_cnt>
  </node>
- <node index="2">
  <type>-</type>
  <link>1:07227301</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>01</lex_id>
  <head_word />
  <head_id />
  <synset_offset>07227301</synset_offset>
  <sense_number>6</sense_number>
  <tag_cnt>1</tag_cnt>
  </node>
- <node index="3">
  <type>-</type>
  <link>1:06642138</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>02</lex_id>
  <head_word />
  <head_id />
  <synset_offset>06642138</synset_offset>
  <sense_number>3</sense_number>
  <tag_cnt>5</tag_cnt>
  </node>
- <node index="4">
  <type>-</type>
  <link>1:06738162</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>03</lex_id>
  <head_word />
  <head_id />
  <synset_offset>06738162</synset_offset>
  <sense_number>2</sense_number>
  <tag_cnt>18</tag_cnt>
  </node>
- <node index="5">
  <type>-</type>
  <link>1:07140659</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>04</lex_id>
  <head_word />
  <head_id />
  <synset_offset>07140659</synset_offset>
  <sense_number>5</sense_number>
  <tag_cnt>3</tag_cnt>
  </node>
- <node index="6">
  <type>-</type>
  <link>1:06674188</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>05</lex_id>
  <head_word />
  <head_id />
  <synset_offset>06674188</synset_offset>
  <sense_number>9</sense_number>
  <tag_cnt>0</tag_cnt>
  </node>
- <node index="7">
  <type>-</type>
  <link>1:07169242</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>06</lex_id>
  <head_word />
  <head_id />
  <synset_offset>07169242</synset_offset>
  <sense_number>4</sense_number>
  <tag_cnt>3</tag_cnt>
  </node>
- <node index="8">
  <type>-</type>
  <link>1:06431740</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>07</lex_id>
  <head_word />
  <head_id />
  <synset_offset>06431740</synset_offset>
  <sense_number>10</sense_number>
  <tag_cnt>0</tag_cnt>
  </node>
- <node index="9">
  <type>-</type>
  <link>1:09537144</link>
  <ss_type>1</ss_type>
  <lex_filenum>18</lex_filenum>
  <lex_filename>noun.person</lex_filename>
  <lex_id>00</lex_id>
  <head_word />
  <head_id />
  <synset_offset>09537144</synset_offset>
  <sense_number>8</sense_number>
  <tag_cnt>0</tag_cnt>
  </node>
- <node index="10">
  <type>-</type>
  <link>1:13627327</link>
  <ss_type>1</ss_type>
  <lex_filenum>23</lex_filenum>
  <lex_filename>noun.quantity</lex_filename>
  <lex_id>00</lex_id>
  <head_word />
  <head_id />
  <synset_offset>13627327</synset_offset>
  <sense_number>7</sense_number>
  <tag_cnt>0</tag_cnt>
  </node>
- <node index="11">
  <type>-</type>
  <link>2:00980453</link>
  <ss_type>2</ss_type>
  <lex_filenum>32</lex_filenum>
  <lex_filename>verb.communication</lex_filename>
  <lex_id>00</lex_id>
  <head_word />
  <head_id />
  <synset_offset>00980453</synset_offset>
  <sense_number>1</sense_number>
  <tag_cnt>2</tag_cnt>
  </node>
  </associations>
  </lemma>
  <seconds_to_execute>0.88710308074951</seconds_to_execute>
  </lex>

Thai
โค๊ด:
The XML page cannot be displayed 
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.


--------------------------------------------------------------------------------

An invalid character was found in text content. Error processing resource 'http://localhost/visuwords/v2.0/lex.php?find=ทดสอบ'...

<b>Notice</b>:  Undefined index: 
อาการดีขึ้นคือ Eng ออก แต่ Thai ดูเหมือนมันไม่รับเลยครับ Lips Sealed
อย่างน้อยมันน่าจะออกแบบนี้น่ะครับ

โค๊ด:
<?xml version="1.0" encoding="utf-8" ?> 
- <!--  generated by Visuwords(TM) xml.php ... visuwords.com
  -->
- <!--  (c) 2007 dunnbypaul.net
  -->
- <lex>
- <lemma>
  <identity>ทดสอบ</identity>
  <associations />
  </lemma>
  <seconds_to_execute>0.89594912528992</seconds_to_execute>
  </lex>

link ไฟล์ผมตามข้างล่างนี้เลยครับ เวลาเรียกก็ตามนี้ครับ http://localhost/lex.php?find=word หรือ lex.php?find=ทดสอบ ก็ได้ครับ
ขอรบกวนพี่ๆอีกทีหน่อยครับ ผมจนปัญญาแล้วครับ wanwan006

http://www.mediafire.com/?adohmmjotmj

คือไฟล์มันเป็น Open source น่ะครับ ผมอยากจะแก้ให้มันอ่านภาษาไทยให้ได้น่ะครับ แต่ทำยังไงก็ไม่ออกซักที ขอความกรุณาจากทุกๆท่านด้วยนะครับ  wanwan008
บันทึกการเข้า
nheuoi
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 6



ดูรายละเอียด
« ตอบ #5 เมื่อ: 20 มีนาคม 2010, 12:03:39 »

คราวนี้มีคนแนะนำให้ใช้ utf8_encode() ตัวแปรที่รับเข้ามาเป็นภาษาไทย ได้ว่าขึ้นเป็น tag ให้แต่มันเอาไปใช้หาข้อมูลไม่ได้อ่ะครับ มันกลายเป็นภาษาขอมเลยอ่ะ ทำไงดีครับ หรือผมทำอะไรผิดอ่ะครับ
โค๊ด:
  <?xml version="1.0" encoding="utf-8" ?> 
- <!--  generated by Visuwords(TM) xml.php ... visuwords.com
  -->
- <!--  (c) 2007 dunnbypaul.net
  -->
- <lex>
  <br />
  <b>Notice</b>
  : Undefined index: ¡ in
  <b>C:\Apache2\htdocs\visuwords\V2.0\class\dictionary.php</b>
  on line
  <b>322</b>
  <br />
- <lemma>
  <identity>¡Ò</identity>  <<< มันเป็นภาษาขอมเลยอ่ะ
  <associations />
  </lemma>
  <seconds_to_execute>1.0612559318542</seconds_to_execute>
  </lex>
ขอความช่วยเหลือด้วยคร้าบบบบ   wanwan031
บันทึกการเข้า
naitam
คนรักเสียว
*

พลังน้ำใจ: 2
ออฟไลน์ ออฟไลน์

กระทู้: 150



ดูรายละเอียด
« ตอบ #6 เมื่อ: 20 มีนาคม 2010, 18:23:03 »

ยังไม่ได้อ่านอะไรทั้งหมดนะครับ , ตาลาย , เลยมั่วตอบว่าลองเป็น
<?xml version="1.0" encoding="windows-874"?>
บันทึกการเข้า
ball6847
เจ้าพ่อบอร์ดเสียว
*

พลังน้ำใจ: 212
ออฟไลน์ ออฟไลน์

กระทู้: 4,174



ดูรายละเอียด
« ตอบ #7 เมื่อ: 20 มีนาคม 2010, 19:14:23 »

ลองใส่ไว้ ก่อนโค้ดอื่นๆจะรัน

error_reporting(E_ERROR | E_WARNING | E_PARSE);

ไม่รู้ error ตรงไหน แต่เวลาจะตรวจสอบ error ของ xml อย่าไปเช็คจาก parser ของ browser เพราะมันก็ไม่รู้หรอก ให้ view source ดูถึงจะเห็นโค้ด xml จริงๆ แล้วเราถึงจะรู้ว่ามันผิดยังงัย (หมายถึงถ้าเรารู้ syntax ของ xml นะคับ) อย่างกรณีหลังนี้ที่มัน error เพราะว่า php ดันแสดง error ออกมาใน xml ทำให้โครงสร้าง xml มันผิด โค้ดที่ผมให้ไปข้างบนนั่นหมายถึงว่าไม่ต้องแสดง error แบบ notice

ปล. ถ้า error อีก ลอง view source แล้วเอาโครงสร้าง xml ที่มัน error มาโพสท์คงจะมีคนช่วยได้เยอะ
บันทึกการเข้า

@@@
Administrator
สมุนแก๊งเสียว
*

พลังน้ำใจ: 33
ออฟไลน์ ออฟไลน์

กระทู้: 634



ดูรายละเอียด เว็บไซต์
« ตอบ #8 เมื่อ: 24 มีนาคม 2010, 09:29:26 »

ยังไม่ได้อ่านอะไรทั้งหมดนะครับ , ตาลาย , เลยมั่วตอบว่าลองเป็น
<?xml version="1.0" encoding="windows-874"?>
แก้ตามความเห็นนี้เลยครับ
หรือ เป็น <?xml version="1.0" encoding="tis-620"?> ก็ได้ครับ
เพราะได้มีการรับค่าภาษาไทยแบบ get ครับ เลยต้องระบุ encoding ให้ถูกต้องครับ
บันทึกการเข้า

รับซื้อเว็บ 100uip ต่อวันขึ้นไป EA Forex
jenovazac
คนรักเสียว
*

พลังน้ำใจ: 6
ออฟไลน์ ออฟไลน์

กระทู้: 134



ดูรายละเอียด เว็บไซต์
« ตอบ #9 เมื่อ: 25 มีนาคม 2010, 22:38:58 »

ประมาณนี้ ครับ

header("Content-Type: application/xml");


print("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<rss version=\"0.91\">\n<channel>\n");

Data.....


echo("</channel>\n</rss>\n");


ส่วนการดึงข้อมูลออกจาก ฐานข้อมูล ให้ดึงเป็น UTF8 ใส่ต่อจาก mysql_select_db
mysql_query("set character_set_results=utf8");
mysql_query("set character_set_connection=utf8");
mysql_query("set character_set_client=utf8");


ผมทำใช้อยู่ปัจจุบันครับ
บันทึกการเข้า
nheuoi
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 6



ดูรายละเอียด
« ตอบ #10 เมื่อ: 21 เมษายน 2010, 23:35:25 »

ขอบคุณ naitam , ball6847 , konlata , jenovazac มากครับสำหรับทุกคำแนะนำ
ขอโทษด้วยครับที่หายไป 1 เดือนเนื่องจากติดภาระบางอย่างที่ทำให้ไม่สามารถออนไลน์ได้ร่วมเดือนครับ Tongue

หลังจากที่ลองมาแล้วปรากฏว่า เปลี่ยน encoding ให้เป็น tis-620 หรือ windows-874 สามารถออกผลลัพธ์อักษรภาษาไทยได้ครับ (ตรง identity ครับ) :'(
โค๊ด:
<?xml version="1.0" encoding="tis-620" ?> 
- <!--  generated by Visuwords(TM) xml.php ... visuwords.com
  -->
- <!--  (c) 2007 dunnbypaul.net
  -->
- <lex>
- <lemma>
  <identity>คำ</identity>
- <associations>
- <node index="1">
  <type>-</type>
  <link>1:ก06286395</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>00</lex_id>
  <head_word />
  <head_id />
  <synset_offset>ก06286395</synset_offset>
  <sense_number>1</sense_number>
  <tag_cnt>117</tag_cnt>
  </node>
- <node index="2">
  <type>-</type>
  <link>1:07227301</link>
  <ss_type>1</ss_type>
  <lex_filenum>10</lex_filenum>
  <lex_filename>noun.communication</lex_filename>
  <lex_id>01</lex_id>
  <head_word />
  <head_id />
  <synset_offset>07227301</synset_offset>
  <sense_number>6</sense_number>
  <tag_cnt>1</tag_cnt>
  </node>
  </associations>
  </lemma>
  <seconds_to_execute>1.0459990501404</seconds_to_execute>
  </lex>
รู้สึกเริ่มดีขึ้นแล้ว แต่หลังจากนั้นผมต้องเอาผลลัพธ์ XML นี้ไปแสดงผลใน Flash script อีกที แต่มันกลายเป็นแบบนี้ครับ  Shocked

ในรูปตรงที่เห็นเป็น "¤�/identity>" น่ะครับ ที่จริงมันควรออกมาเป็น  "คำ" เช่นแบบนี้

เหมือนว่า flash มันอ่านค่าที่เป็นภาษาไทยไม่ได้ ผมเลยลองพยายามหาข้อมูลดู เลยเจอเวปนี้น่ะครับ
http://www.thaiflashdev.com/home/index.php?topic=1844.0
http://www.thaiflashdev.com/home/index.php/topic,4685.0.html
http://www.thaiflashdev.com/home/index.php/topic,4685.0.html
เหมือนจะสรุปว่า flash อ่านได้แค่ utf-8 มั้ง เพราะผมลองใช้ tis-620 หรือ windows-874 แล้วก็ได้แบบตามรุปบนเลยครับ Lips Sealed
ตอนนี้เหมือนวกกลับมาปัญหาเดิมคือทำไงให้มันออกมาเป็น UTF-8 ให้ได้น่ะครับ ผมลองแปะ code ตามที่คุณ jenovazac แนะมาแล้ว กลายเป็นว่ามัน error เลยครับ
โค๊ด:
Internet Explorer cannot display this feed 
 
   This feed contains code errors.
     Go back to the previous page.
 
     More information

ขอความกรุณาทุกท่านอีกทีครับ ทำไงให้มันออกมาเป็น UTF-8 ภาษาไทยได้ครับ wanwan006
บันทึกการเข้า
@@@
Administrator
สมุนแก๊งเสียว
*

พลังน้ำใจ: 33
ออฟไลน์ ออฟไลน์

กระทู้: 634



ดูรายละเอียด เว็บไซต์
« ตอบ #11 เมื่อ: 12 พฤษภาคม 2010, 10:58:05 »

flash อ่านภาษาไทยตรงๆไม่ได้ครับ(ตามที่เข้าใจ)
เราต้องแปลงค่าภาษาไทยให้flash ครับ
ถ้าใช้ php ก็ rawurlencode()
บันทึกการเข้า

รับซื้อเว็บ 100uip ต่อวันขึ้นไป EA Forex
หน้า: [1]   ขึ้นบน
พิมพ์