ตัด string แล้วตัวอักษรสุดท้ายเป็นต่างดาว ??

วันนี้ประสบปัญหาจากการตัด string จากฟังชั่น substr() แล้วตัวสุดท้ายเป็นภาษาต่างดาวซะงั้น
เลยถามพี่กู(เกิ้ล) อีกแล้ว ได้ความว่า ถ้าใช้กับ encoding ที่เป็น tis-620 ไม่มีปัญหา แต่จะมีัปัญหากับ utf-8
ได้วิธีแก้มาดังนี้

ให้ใช้ iconv_substr() แทน เพราะสามารถระบุึ encoding ของ output ได้ด้วย

ตัวอย่าง : iconv_substr($text, 0, 30, “UTF-8″);

โดย parameter ตัวสุดท้ายจะเป็น Character encoding ครับ

เอาไปลองกันดูนะค้าบบบ 

ที่มา http://dexterian.exteen.com/20080726/string

 

 

Tags:

2 Responses to “ตัด string แล้วตัวอักษรสุดท้ายเป็นต่างดาว ??”

  1. Anonymous Says:

    มีประโยชน์ดีนะ

  2. wow gold Says:

    This is my first time comment at your blog.
    Good recommended website.

Leave a Reply

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word