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

  • SEARCH
  • Home
  • 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 6252643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:50:30+00:00 2026-05-24T13:50:30+00:00

I am using curl to get a json file which can be located here:

  • 0

I am using curl to get a json file which can be located here: (It’s way too long to copy paste it): http://www.opap.gr/web/services/rs/betting/availableBetGames/sport/program/4100/0/sport-1.json?localeId=el_GR

After that i use json_decode to get the assosiative array.Till here everything seems ok.When i am using var_dump the characters inside the array are in Greek.After that i am using the following code:

    $JsonClass = new ArrayToXML();
    $mydata=$JsonClass->toXml($json);

class ArrayToXML
{

public static function toXML( $data, $rootNodeName = 'ResultSet', &$xml=null ) {

    // turn off compatibility mode as simple xml throws a wobbly if you don't.
   // if ( ini_get('zend.ze1_compatibility_mode') == 1 ) ini_set ( 'zend.ze1_compatibility_mode', 0 );
    if ( is_null( $xml ) ) //$xml = simplexml_load_string( "" );
        $xml = simplexml_load_string("<?xml version='1.0' encoding='UTF-8'?><$rootNodeName />");

    // loop through the data passed in.
    foreach( $data as $key => $value ) {

        $numeric = false;

        // no numeric keys in our xml please!
        if ( is_numeric( $key ) ) {
            $numeric = 1;
            $key = $rootNodeName;
        }

        // delete any char not allowed in XML element names
        `enter code here`$key = preg_replace('/[^a-z0-9\-\_\.\:]/i', '', $key);

        // if there is another array found recrusively call this function
        if ( is_array( $value ) ) {
            $node = ArrayToXML::isAssoc( $value ) || $numeric ? $xml->addChild( $key ) : $xml;

            // recrusive call.
            if ( $numeric ) $key = 'anon';
            ArrayToXML::toXml( $value, $key, $node );
        } else {

            // add single node.
            $value = htmlentities( $value );
            $xml->addChild( $key, $value );
        }
    }

    // pass back as XML
    return $xml->asXML();


}
public static function isAssoc( $array ) {
    return (is_array($array) && 0 !== count(array_diff_key($array, array_keys(array_keys($array)))));
}

}

And here comes the problem .All the greek characters inside the result are in some strange characters &Icirc;?&Icirc;?&Icirc;&yen;&Icirc;?&Icirc;?&Icirc;&iexcl;&Icirc;&copy;&Icirc;&pound;&Icirc;?&Icirc;? for example.I really don’t know what am i doing wrong.I am really bad with encoding /decoding things :(.

And to make this a bit more clear:

Here is how the assosiative array (on of the parts that i have the problem with) looks like:

{ ["resources"]=> array(4) { ["team-4833"]=> string(24) "ΛΕΥΚΟΡΩΣΙΑ U21" ["t-429"]=> string(72) "ΠΡΟΚΡΙΜΑΤΙΚΑ ΕΥΡΩΠΑΪΚΟΥ ΠΡΩΤΑΘΛΗΜΑΤΟΣ" ["t-429-short"]=> string(6) "ΠΕΠ" ["team-15387"]=> string(16) "ΕΛΛΑΔΑ U21" } ["locale"]=> string(5) "el_GR" } ["relatedNum"]=> NULL }

And here is what i get after the use of simplexml

<resources><team-4833>&Icirc;?&Icirc;?&Icirc;&yen;&Icirc;?&Icirc;?&Icirc;&iexcl;&Icirc;&copy;&Icirc;&pound;&Icirc;?&Icirc;? U21</team-4833><t-429>&Icirc;&nbsp;&Icirc;&iexcl;&Icirc;?&Icirc;?&Icirc;&iexcl;&Icirc;?&Icirc;?&Icirc;?&Icirc;&curren;&Icirc;?&Icirc;?&Icirc;? &Icirc;?&Icirc;&yen;&Icirc;&iexcl;&Icirc;&copy;&Icirc;&nbsp;&Icirc;?&Icirc;&ordf;&Icirc;?&Icirc;?&Icirc;&yen; &Icirc;&nbsp;&Icirc;&iexcl;&Icirc;&copy;&Icirc;&curren;&Icirc;?&Icirc;?&Icirc;?&Icirc;?&Icirc;?&Icirc;?&Icirc;&curren;&Icirc;?&Icirc;&pound;</t-429><t-429-short>&Icirc;&nbsp;&Icirc;?&Icirc;&nbsp;</t-429-short><team-15387>&Icirc;?&Icirc;?&Icirc;?&Icirc;?&Icirc;?&Icirc;? U21</team-15387></resources><locale>el_GR</locale></lexicon><relatedNum></relatedNum></betGames>

Thanks in advance for your replies.

PS:I have also <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> in the page i display the result but it doesnt help.


I still didn’t find a solution with that so i used a different approach something like Yannis suggested.I saved the XML in a file using the class i found here http://www.phpclasses.org/package/1826-PHP-Store-associative-array-data-on-file-in-XML.html .

After that i load the xml with simplexml_load_file and i used xslt to access the data in all nodes and store it in my database.It worked fine that way .If anyone still wants to try and explain me why it doesn’t work with the way i tried to do it at the start feel free (Just for the learning purpose :p)Thanks for your replies :).

  • 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-24T13:50:31+00:00Added an answer on May 24, 2026 at 1:50 pm

    There is no need – The current json is given in an xml format as well here apparently:

    http://www.opap.gr/web/services/rs/betting/availableBetGames/sport/program/4100/0/sport-1.xml?localeId=el_GR

    Just had to play with the url parameters a bit 🙂

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

Sidebar

Related Questions

I'm using cURL to get the XML file for my Twitter friend's timeline. (API
Answer : Implemented using Curl... $file = http://abc.com/data//output.txt; $ch = curl_init($file); $fp = @fopen(out.txt,
When using PHP I can use file_get_contents or cURL to get a URL. jQuery
I'm trying to get character data from www.wowarmory.com using PHP and cURL. The code
I am using curl like this: curl -s -F uploaded_file=@/path_to_file;type=text/html -F output=soap12 http://localhost/w3c-markup-validator/check >text.xml
I'm using curl to make php send an http request to some website somewhere
file_get_contents(php://input) or $HTTP_RAW_POST_DATA - which one is better to get the body of JSON
I'm trying to get twitter update_profile_image to work using OAuth. I was using curl
I'm using cURL to get a web page and present to our users. Things
When I try to use curl or file_get_contents to read something like http://example.com/python/json/ from

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.