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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:31:35+00:00 2026-06-05T04:31:35+00:00

I would like to replace the € sign in $XML_COMMENT with euros before adding

  • 0

I would like to replace the € sign in $XML_COMMENT with “euros” before adding to a xml file.

The € sign not being a utf-8 character I get and error message from simplexml

Warning: SimpleXMLElement::addAttribute(): string is not in UTF-8 in ...
Warning: SimpleXMLElement::asXML(): output conversion failed due to conv error, bytes 0x82 0x26 0x61 0x6D in ....

The euro sign appears in the MySQL (utf-8) database as ‘€’

But appears correctly in the textarea on the webpage.

I tried to use these different str_replace

$XML_COMMENT=str_replace('€','euros',$XML_COMMENT)
$XML_COMMENT=str_replace('€','euros',$XML_COMMENT)
$XML_COMMENT=str_replace(chr(128),'euros',$XML_COMMENT)
$XML_COMMENT=str_replace(chr(0xE2).chr(0×82).chr(0xAC),'euros',$XML_COMMENT)
$XML_COMMENT=str_replace(chr(0x82).chr(0x26).chr(0x61).chr(0x6D),'euros',$XML_COMMENT)

without success

FYI: I’m using utf-8 everywhere (MySQL, Web Page and XML)

Here’s my code

// ? : $XML_COMMENT= "bla bla bla € bla bla bla";
// ? : $XML_COMMENT= "bla bla bla € bla bla bla";
// expected : $XML_COMMENT= "bla bla bla euros bla bla bla";

$ProductLog_XML = simplexml_load_file($file);
$ProductUpdate = $ProductLog_XML->order->product->addChild('update');
$ProductUpdate->addAttribute('comment',$XML_COMMENT);
$fp=fopen(file, "w");
fwrite($fp, $ProductLog_XML->asXML());
fclose($fp);

Is there any alternative using regex / preg_replace ?

  • 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-05T04:31:36+00:00Added an answer on June 5, 2026 at 4:31 am

    You can try htmlentities() to convert all entities including the euro sign, so they appear like €.

    I would use it in the following manner: htmlentities($str, ENT_QUOTES|"ENT_HTML401", "UTF-8", true)

    You may choose to use: htmlentities($XML_COMMENT, ENT_QUOTES | ENT_IGNORE, "UTF-8", true). For a full explanation of what the flags change, visit the link below.
    As requested by OP @baptme (see comments).

    Source: php.net reference

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

Sidebar

Related Questions

I would like to replace the first character ' x ' with the number
I would like to replace the following: =Dark4Red with =\Dark4Red\ The = sign and
We have a property file (name, value key pairs) and would like to replace
I would like to replace drop down list (that has on change event that
I would like to replace blank spaces/white spaces in a string with commas. STR1=This
I would like to replace a part of the image with my image in
I would like to replace extra spaces (instances of consecutive whitespace characters) with one
I have the following table and would like to replace the string text of
I have this sample string where I would like to replace the star with
in my script I check some files and would like to replace a part

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.