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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:49:34+00:00 2026-05-15T12:49:34+00:00

I am taking an XML file and reading it into various strings, before writing

  • 0

I am taking an XML file and reading it into various strings, before writing to a database, however I am having difficulty with German characters.

The XML file starts off

<?xml version="1.0" encoding="UTF-8"?>

Then an example of where I am having problems is this part

<name><![CDATA[PONS Großwörterbuch Deutsch als Fremdsprache Android]]></name>

My PHP has this relevant section

$dom = new DOMDocument();
$domNode = $xmlReader->expand();
$element = $dom->appendChild($domNode);
$domString = utf8_encode($dom->saveXML($element));
$product = new SimpleXMLElement($domString);

//read in data
$arr = $product->attributes();
$link_ident = $arr["id"];
$link_id =  $platform . "" . $link_ident;
$link_name = $product->name;

So $link_name becomes PONS GroÃwörterbuch Deutsch als Fremdsprache Android

I then did a

$link_name = utf8_decode($link_name);

Which when I echoed back in terminal worked fine

PONS GroÃwörterbuch Deutsch als Fremdsprache Android as is now 
PONS Großwörterbuch Deutsch als Fremdsprache Android after utf8decode 

However when it is written into my database it appears as:

PONS Kompaktwörterbuch Deutsch-Englisch (Android)

The collation for link_name in MysQL is utf8_general_ci

How should I be doing this to get it correctly written into my database?

This is the code I use to write to the database

$link_name = utf8_decode($link_name);
$link_id = mysql_real_escape_string($link_id);
$link_name = mysql_real_escape_string($link_name);
$description = mysql_real_escape_string($description);
$metadesc = mysql_real_escape_string($metadesc);
$link_created = mysql_real_escape_string($link_created);
$link_modified = mysql_real_escape_string($link_modified);
$website = mysql_real_escape_string($website);
$cost = mysql_real_escape_string($cost);
$image_name = mysql_real_escape_string($image_name);
$query = "REPLACE into jos_mt_links
(link_id, link_name, alias, link_desc, user_id, link_published,link_approved, metadesc, link_created, link_modified, website, price)
VALUES ('$link_id','$link_name','$link_name','$description','63','1','1','$metadesc','$link_created','$link_modified','$website','$cost')";
echo $link_name . " has been inserted ";

and when I run it from shell I see

PONS Kompaktwörterbuch Deutsch-Englisch (Android) has been inserted
  • 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-15T12:49:34+00:00Added an answer on May 15, 2026 at 12:49 pm

    You’ve got a UTF-8 string from an XML file, and you’re putting it into a UTF-8 database. So there is no encoding or decode to be done, just shove the original string into the database. Make sure you’ve used mysql_set_charset('utf-8') first to tell the database there are UTF-8 strings coming.

    utf8_decode and utf8_encode are misleadingly named. They are only for converting between UTF-8 and ISO-8859-1 encodings. Calling utf8_decode, which converts to ISO-8859-1, will naturally lose any characters you have that don’t fit in that encoding. You should generally avoid these functions unless there’s a specific place where you need to be using 8859-1.

    You should not consider what the terminal shows when you echo a string to be definitive. The terminal has its own encoding problems and especially under Windows it is likely to be impossible to output every character properly. On a Western Windows install the system code page (which the terminal will use to turn the bytes PHP spits out into characters to display on-screen) will be code page 1252, which is similar to but not the same as ISO-8859-1. This is why utf8_decode, which spits out ISO-8859-1, appeared to make the text appear as you expected. But that’s of little use. Internally you should be using UTF-8 for all strings.

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

Sidebar

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.