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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:28:53+00:00 2026-05-24T10:28:53+00:00

I am trying to write some content into an XML file, yet I do

  • 0

I am trying to write some content into an XML file, yet I do have problems with special characters.

The content I’d like to write is submitted to the script via $_GET, so I assume it is properly decoded into UTF-8 content.

$write = $_GET['content'];

will be fed like:

file.php?content=s%F6per

In the PHP I do the following:

$xml = simplexml_load_file('file.xml');
$newentry = $xml -> addChild('element',$write);
$xml -> asXML($xml_filename);

The XML file that is opened is UTF-8 encoded. When I write content without any of those “problem characters” the asXML will save the file in UTF-8 again. As soon as I insert special characters it gets saved in ANSI encoding, messing up the file as I won’t be able to open it (the script will complain about improper encoding) anymore.

What am I missing? Reading the manual gives me the impression that I should be doing everything ok (i.e. not messing with the $_GET['content']), so I unfortunately have no clue.

Thanks so much!

  • 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-24T10:28:54+00:00Added an answer on May 24, 2026 at 10:28 am

    your special characters does not look a UTF-8, but a ISO-8859-1 character

    see here – http://www.degraeve.com/reference/urlencoding.php

    Possible solution

    $newentry = $xml->addChild('element', htmlentities($write));
    

    Or

    $newentry = $xml->addChild('element', iconv('ISO-8859-1', 'UTF-8', $write));
    

    And off-topic, please avoid using $_GET to write something into file or insert into database, is risky

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

Sidebar

Related Questions

I am trying to write some content into file inside my spring controller. Before
Im trying to write a quick plugin that will load some AJAX content into
I'm trying to write some PHP to upload a file to a folder on
I'm trying to write some LINQ To SQL code that would generate SQL like
I'm trying to write some code to work with an htdigest password file. The
I'm trying to write some code to Hide columns if the first 3 characters
I'm trying to write a Greasemonkey script for Facebook and having some trouble with
I am trying to write some code that will open a file, read its
So I have some perl code that goes something like: use strict; use XML::XPath;
I am trying to write a .bat file to automate some shell commands. Most

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.