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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:14:25+00:00 2026-05-18T20:14:25+00:00

I wrote a small PHP script to edit the site news XML file. I

  • 0

I wrote a small PHP script to edit the site news XML file.
I used DOM to manipulate the XML (Loading, writing, editing).

It works fine when writing English characters, but when non-English characters are written, PHP throws an error when trying to load the file.

If I manually type non-English characters into the file – it’s loaded perfectly fine, but if PHP writes the non-English characters the encoding goes wrong, although I specified the utf-8 encoding.

Any help is appreciated.

Update: with the helpful answers, it is solved (read below).

Errors:

Warning: DOMDocument::load()
[domdocument.load]: Entity ‘times’ not
defined in filepath

Warning: DOMDocument::load()
[domdocument.load]: Input is not
proper UTF-8, indicate encoding !
Bytes: 0x91 0x26 0x74 0x69 in filepath

Here are the functions responsible for loading and saving the file (self-explanatory):

function get_tags_from_xml(){
// Load news entries from XML file for display
    $errors = Array();

    if(!$xml_file = load_news_file()){
    // Load file
        // String indicates error presence
        $errors = "file not found";
        return $errors;
    }
    $taglist = $xml_file->getElementsByTagName("text");
    return $taglist;
}
function set_news_lang(){
// Sets the news language
    global $news_lang;

    if($_POST["news-lang"]){
        $news_lang = htmlentities($_POST["news-lang"]);
    }
    elseif($_GET["news-lang"]){
        $news_lang = htmlentities($_GET["news-lang"]);
    }
    else{
        $news_lang = "he";
    }
}
function load_news_file(){
// Load XML news file for proccessing, depending on language 
    global $news_lang;

    $doc = new DOMDocument('1.0','utf-8');
    // Create new XML document
    $doc->load("news_{$news_lang}.xml");
    // Load news file by language
    $doc->formatOutput = true;
    // Nicely format the file

    return $doc;
}
function save_news_file($doc){
// Save XML news file, depending on language 
    global $news_lang;

    $doc->saveXML($doc->documentElement);
    $doc->save("news_{$news_lang}.xml");
}

Here is the code for writing to XML (add news):

<?php ob_start()?>
<?php include("include/xml_functions.php")?>
<?php include("../include/functions.php")?>
<?php get_lang();?>
<?php
//TODO: ADD USER AUTHENTICATION!
if(isset($_POST["news"]) && isset($_POST["news-lang"])){
    set_news_lang();

    $news = htmlentities($_POST["news"]);

    $xml_doc = load_news_file();
    $news_list = $xml_doc->getElementsByTagName("text");
    // Get all existing news from file

    $doc_root_element = $xml_doc->getElementsByTagName("news")->item(0);
    // Get the root element of the new XML document
    $new_news_entry = $xml_doc->createElement("text",$news);
    // Create the submited news entry

    $doc_root_element->appendChild($new_news_entry);
    // Append submited news entry
    $xml_doc->appendChild($doc_root_element);

    save_news_file($xml_doc);

    header("Location: /cpanel/index.php?lang={$lang}&news-lang={$news_lang}");
}
else{
    header("Location: /cpanel/index.php?lang={$lang}&news-lang={$news_lang}");
}
?>
<?php ob_end_flush()?>

Update: with the helpful answers you provided, its solved:
The value submitted by form is non-English, and it contains some HTML entities,
I used htmlentities() on the POST, that made the non-English string unreadable.
Replaced htmlentities() with htmlspecialchars(), and it works like magic.

Conclusion: htmlentities() can ruin non-English strings.

  • 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-18T20:14:26+00:00Added an answer on May 18, 2026 at 8:14 pm

    Character encoding is always a hassle. Make sure the page containing your form, the xml you load into $dom, and the php file itself are also utf-8 encoded, or translate accordingly. Otherwise all your strings won’t be, and handling them as utf-8 won’t work.

    Try this: echo your original news XML onto an empty page. Then switch page encoding in the browser to see which one displays the characters correctly. Repeat this for $news after retrieving the input from the form. This usually provides a clue on where the encoding goes wrong.

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

Sidebar

Related Questions

I am trying to use php. I wrote a small script as instructed in
I wrote a small PHP application several months ago that uses the WordPress XMLRPC
I wrote a small PHP application that I'd like to distribute. I'm looking for
I noticed the other day that a new script I wrote for php 5
I wrote a small executable in C# .NET that manages a .jar file. Our
We wrote a small Windows class library that implements extension methods for some standard
I wrote a small sample of code in C# to capture selected text from
I recently wrote a small tool to generate a class for each tier I
Right now I'm developing mostly in C/C++, but I wrote some small utilities in
I have several small open-source projects that I wrote. All my attempts to find

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.