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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:33:03+00:00 2026-06-13T00:33:03+00:00

I have a simple XML script like this: $file=’example.xml’; if (file_exists($file)) { $xml =

  • 0

I have a simple XML script like this:

$file='example.xml';
if (file_exists($file)) {
    $xml = simplexml_load_file($file);
    $f = fopen('newfile.csv', 'w');

    // array to hold the field names
    $headers = array(); 
    // loop through the first set of fields to get names
    foreach ($xml->Information->children() as $field) { 
        // put the field name into array
        $headers[] = $field->getName(); 
    }
    // print headers to CSV
    fputcsv($f, $headers, ',', '"');

    foreach ($xml->Information as $information) {
        fputcsv($f, get_object_vars($information), ',', '"');
    }
    fclose($f);
}

But if example.xml has a £ sign in it, then in newfile.csv it will show as £.

Is there any way to overcome this? I dont know the encoding of example.xml since it is a remote file that is wget’d in.

  • 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-06-13T00:33:04+00:00Added an answer on June 13, 2026 at 12:33 am

    One way to do it is by detecting the encoding in the file, which you can do by processing the headers in a curl session. There should be a Content-Type. Otherwise, the xml specs, define utf-8 as the basic character set, so you can try to use that.

    You may also use mb_detect_encoding if you don’t want to use curl, but I’ll try to use it first.

    Then, if you want, you can use iconv or mb_convert_encoding to change the type from whatever it is to utf-8 or the charset you prefer and then save the file.

    Bye

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

Sidebar

Related Questions

i have this very simple download page to get an xml file. the script
I have a Perl script that reads a simple .csv file like below- header1,header2,header3,header4
I have a simple xml file that looks like this: <?xml version=1.0 encoding=UTF-8 standalone=yes
I have a simple XML file that looks like this: <?xml version=1.0 ?> <devices>
I have this simple XML file : <?xml version=1.0 encoding=utf-8 ?> <Artists> <artist artistId=1>
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
i have a simple xml file in a wcf service that i am trying
I have a simple xml file and I want to remove everything before the
I have a really simple XML file that I'm trying to read, but I
I have write a script for renaming it is like this for i in

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.