Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3856036
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:52:06+00:00 2026-05-19T17:52:06+00:00

I’m trying to get Thai characters from a website. I’ve tried: $rawChapter = file_get_contents(URL);

  • 0

I’m trying to get Thai characters from a website. I’ve tried:

$rawChapter = file_get_contents("URL");
$rawChapter = mb_convert_encoding($rawChapter, 'UTF-8', mb_detect_encoding($rawChapter, 'UTF-8, ISO-8859-1', true));

When I do this then the characters come back like:

¡ÅѺ˹éÒáá¾ÃФÑÁÀÕÃìÀÒÉÒä·Â©ºÑº

But if I take the source of the page I’m trying to load and save that into my own .htm file on my localhost as a utf8 file then it loads the Thai characters correctly. Only when I try to load it from the site directly it breaks.

How can I fix this? What could be the problem?

I’ve also tried adding this context:

$context = stream_context_create(array(
            'http' => array(
                'method' => 'POST',
                'header' => implode("\r\n", array(
                    'Content-type: application/x-www-form-urlencoded',
                    'Accept-Language: en-us,en;q=0.5',
                    'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'
                ))
            )
        ));

I’ve tried adding it alone, I’ve tried adding it with the mb_convert_encoding()… I feel like I’ve tried all combinations of this stuff and no success.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:52:07+00:00Added an answer on May 19, 2026 at 5:52 pm

    Change your Accept-Charset to UTF-8 because ISO-8859-1 does not support Thai characters. If you are running your PHP script on a windows machine, you may also use the windows-874 charset, and you may also try adding this header :

    Content-Language: th
    

    But in most cases, UTF-8 will handle pretty much most characters or character sets without any other declaration.

    ** UPDATE **

    Very strange, but this works for me.

    $opts = array(
      'http'=>array(
        'method'=>"GET",
        'header'=> implode("\r\n", array(
                       'Content-type: text/plain; charset=TIS-620'
                       //'Content-type: text/plain; charset=windows-874'  // same thing
                    ))
      )
    );
    
    $context = stream_context_create($opts);
    
    //$fp = fopen('http://thaipope.org/webbible/01_002.htm', 'rb', false, $context);
    //$contents = stream_get_contents($fp);
    //fclose($fp);
    $contents = file_get_contents("http://thaipope.org/webbible/01_002.htm",false, $context);
    
    header('Content-type: text/html; charset=TIS-620');
    //header('Content-type: text/html; charset=windows-874');  // same thing
    
    echo $contents;
    

    Apparently, I was wrong for this one about UTF-8. See here for more details. Though you can still have an UTF-8 output :

    $in_charset = 'TIS-620';   // == 'windows-874'
    $out_charset = 'utf-8';
    
    $opts = array(
      'http'=>array(
        'method'=>"GET",
        'header'=> implode("\r\n", array(
                       'Content-type: text/plain; charset=' . $in_charset
                    ))
      )
    );
    
    $context = stream_context_create($opts);
    
    $contents = file_get_contents("http://thaipope.org/webbible/01_002.htm",false, $context);
    if ($in_charset != $out_charset) {
        $contents = iconv($in_charset, $out_charset, $contents);
    }
    
    header('Content-type: text/html; charset=' . $out_charset);
    
    echo $contents;   // output in UTF-8
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.