0

I've got the folowing xml string in php:

$str="<name>An☢maly</name>";

I then do the following:

$tmp=new SimpleXMLElement($str);

if I do:

echo $tmp->name;

I get this:

An☢maly

When I do:

echo utf8_decode($tmp->name);

I get:

An?maly

How do I get PHP to display that funny character, it also does it with the following:

ƎnƔy™ = ?n?y?

2 Answers 2

1

Try use

header('Content-type:text/html;charset=utf-8');

before output (if you use browser)

P.S: An☢maly - this is output when browser render page in "ISO-8859-1" charset instead "UTF-8"

Sign up to request clarification or add additional context in comments.

1 Comment

This was the browser confusing me thanks, the xml document was UTF-8 from the beginning but html was not defined.
1

That's strange, I'm doing the exact same thing and it is displaying properly in web browser:

<?php
$str="<xml><name>ƎnƔy™</name></xml>";
$tmp=new SimpleXMLElement($str);
echo $tmp->name;
?>

I noticed that it didn't work properly unless I saved the source file as a UTF8 encoded file. I'm using Programmer's Notepad and clicked file > properties and changed the 'Encoding' parameter to UTF-8 to achieve this.

Also, UTF8 characters will not print correctly on windows command line, which may also be your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.