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 6019521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:26:02+00:00 2026-05-23T03:26:02+00:00

I’m busy trying to process the following RSS feed: Yahoo Search RSS , using

  • 0

I’m busy trying to process the following RSS feed: Yahoo Search RSS, using the following code once the data is fetched:

$response = simplexml_load_string($data);

However, 99% of the chinese characters and strings disappear when I interrogate the simple xml object.

I’ve tried converting the incoming data to utf8 by doing:

$data = iconv("UTF-8", "UTF-8//TRANSLIT", $data);

But this also doesn’t help.

Before the data hits simplexml_load_string its 100% fine. But afterwards, its not.

Any ideas?

  • 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-23T03:26:03+00:00Added an answer on May 23, 2026 at 3:26 am

    What you describe sounds like an encoding issue. Encoding is like a chain, if it get’s broken at one part of the processing, the data can be damaged.

    When you request the data from the RSS server, you will get the data in a specific character encoding. The first thing you should find out is the encoding of that data.

    Data URL: http://tw.blog.search.yahoo.com/rss?ei=UTF-8&p=%E6%95%B8%E4%BD%8D%E6%99%82%E4%BB%A3%20%E9%9B%9C%E8%AA%8C&pvid=QAEnPXeg.ioIuO7iSzUg9wQIc1LBPk3uWh8ABnsa
    

    According to the website headers, the encoding is UTF-8. This is the standard XML encoding.

    However if the data is not UTF-8 encoded while the headers are saying so, you need to find out the correct encoding of the data and bring it into UTF-8 before you go on.

    Next thing to check is if simplexml_load_string() is able to deal with UTF-8 data.

    I do not use simplexml, I use DomDocument. So I can not say if or not. However I can suggest you to use DomDocument instead. It definitely supports UTF-8 for loading and all data it returns is encoded in UTF-8 as well. You should safely assume that simplexml handles UTF-8 properly as well however.

    Next part of the chain is your display. You write that your data is broken. How can you say so? How do you interrogate the simplexml object?


    Revisiting the Encoding Chain

    As written, encoding is like a chain. If one element breaks, the overall result is damaged. To find out where it breaks, each element has to be checked on it’s own. The encoding you aim for is UTF-8 here.

    • Input Data: All Checks OK:
    • Check: Does the encoding data seems to be UTF-8? Result: Yes. The input data aquired from the data URL given, does validate the UTF-8 encoding. This could be properly tested with the data provided.
    • Check: Does the raw xml data mark itself as being UTF-8 encoded? Result: Yes. This could be verified within the first bytes that are: <?xml version="1.0" encoding="UTF-8" ?>.
    • Simple XML Data:
    • Check: Does simple_xml support the UTF-8 encoding? Result: Yes.
    • Check: Does simple_xml return values in the UTF-8 encoding? Result: Yes and No. Generally simple_xml support properties containing text that is UTF-8 encoded, however a var_dump() of the simple_xml object instance with the xml data suggests that it does not support CDATA. CDATA is used in the data in question. CDATA elements will get dropped.

    At this point this looks like the error you are facing. However you can convert all CDATA elements into text. To do this, you need to specify an option when loading the XML data. The option is a constant called LIBXML_NOCDATA and it will merge CDATA as text nodes.

    The following is an example code I used for the tests above and demonstrates how to use the option:

    $data_url = 'http://tw.blog.search.yahoo.com/rss?ei=UTF-8&p=%E6%95%B8%E4%BD%8D%E6%99%82%E4%BB%A3%20%E9%9B%9C%E8%AA%8C&pvid=QAEnPXeg.ioIuO7iSzUg9wQIc1LBPk3uWh8ABnsa';
    $xml_data = file_get_contents($data_url);
    
    $inspect = 256;
    echo "First $inspect bytes out of ", count($xml_data),":\n", wordwrap(substr($xml_data, 0, $inspect)), "\n";
    echo "UTF-8 test: ", var_dump(can_be_valid_utf8_statemachine($xml_data)), "\n";
    
    $simple_xml = simplexml_load_string($xml_data, null, LIBXML_NOCDATA);
    var_dump($simple_xml);
    
    
    /**
     * Bitwise check a string if it would validate 
     * as utf-8.
     *
     * @param string $str
     * @return bool
     */
    function can_be_valid_utf8_statemachine( $str ) { 
        $length = strlen($str); 
        for ($i=0; $i < $length; $i++) { 
            $c = ord($str[$i]); 
            if ($c < 0x80) $n = 0; # 0bbbbbbb 
            elseif (($c & 0xE0) == 0xC0) $n=1; # 110bbbbb 
            elseif (($c & 0xF0) == 0xE0) $n=2; # 1110bbbb 
            elseif (($c & 0xF8) == 0xF0) $n=3; # 11110bbb 
            elseif (($c & 0xFC) == 0xF8) $n=4; # 111110bb 
            else return false; # Does not match 
            for ($j=0; $j<$n; $j++) { # n bytes matching 10bbbbbb follow ? 
                if ((++$i == $length) || ((ord($str[$i]) & 0xC0) != 0x80)) 
                    return false; 
            } 
        } 
        return true; 
    }
    

    I assume that this will fix your issue. If not DomDocument is able to handle CDATA elements. As the encoding chain is not further tested, you might still get encoding issues in the further processing of the data, so take care that you keep the encoding up to the output.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
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
I have a French site that I want to parse, but am running into

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.