php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27858 simpleXML and cyrillic bug
Submitted: 2004-04-04 04:12 UTC Modified: 2004-04-04 06:53 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: selecter at spray dot se Assigned:
Status: Not a bug Package: SimpleXML related
PHP Version: 5.0.0RC1 OS: linux gentoo
Private report: No CVE-ID: None
 [2004-04-04 04:12 UTC] selecter at spray dot se
Description:
------------
Character coding mess...
index.php and example.xml are saved in koi8-r encoding

Reproduce code:
---------------
index.php:
<?php
include 'example.xml';
$xml = simplexml_load_string($xmlstr);

function open_linkset($num)
{
	global $xml;
	eval("foreach(\$xml->linkset[$num]->mylink as \$mylink)
	{
		generate_link(\$mylink->title, \$mylink->href);
	}");
}

function generate_link($title, $href)
{
	global $link;
	$link[]='<a href="?'.$href.'&open='.$_GET[open].'">'.$title.'</a>';
}

function generate_linkbox()
{
	global $xml, $link;
	$i=0;
	$array_size=sizeof($xml->linkset);
	foreach($xml->linkset as $mylinkset)
	{
		echo '<a href="?open='.$i.'">'.$mylinkset->name.'</a>';
		echo "<br>";

		if(isset($link) && $_GET[open]==$i)
		{
			$k=0;
			$link_array_size=sizeof($link);
			foreach($link as $mylink)
			{
				echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$link[$k];
				if($link_array_size<>$k)echo "<br>";
				$k++;
			}
		}
		$i++;
	}
}

if(isset($_GET[open]))
{
	open_linkset($_GET[open]);
	generate_linkbox();
}else{
	generate_linkbox();
}
?>

example.xml:
<?php
$xmlstr = <<<XML
<?xml version='1.0' encoding='koi8-r' standalone='yes'?>
<linkbox>
	<linkset>
		<name>&#1043;&#1083;&#1072;&#1074;&#1085;&#1072;&#1103;</name>
		<mylink>
			<href>to=fotos</href>
			<title>Fotos</title>
		</mylink>

		<mylink>
			<href>to=art</href>
			<title>Art</title>
		</mylink>
	</linkset>

	<linkset>
		<name>Discussion</name>
		<mylink>
			<href>to=forum</href>
			<title>Forum</title>
		</mylink>

		<mylink>
			<href>to=guestbook</href>
			<title>Guestbook</title>
		</mylink>
	</linkset>
</linkbox>
XML;
?>

Expected result:
----------------
Executing index.php I expect to see 2 linksets:
&#1043;&#1083;&#1072;&#1074;&#1085;&#1072;&#1103;
Discussion

Actual result:
--------------
The actual result after executing index.php:
Главная
Discussion

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-04-04 06:53 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

Like any other XML parser simplexml interprets the XML entities to normal characters in UTF-8.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 23:01:29 2024 UTC