I used the following XML and PHP code to parse the Thai Characters and it didn't come out any result. But it works on Demo page. Please advise.
<?xml version=\"1.0\"?><root><userId>phyo</userId><templateName>hello world</templateName><conditions><condition> [growerName] = 'ละไม พันธุ์นิตย์' </condition></conditions></root>
<?php
require("MagicParser.php");
function myRecordHandler($record)
{
// This is where you write your code to process each record, such as loading a database
// You can display the record contents using PHP's internal print_r() function:
print_r($record);
// The following code will print out each field in your sample data:
print $record["CONDITION"];
}
$data = ""; // string variable contianing the data to parse
MagicParser_parse("string://".$data,"myRecordHandler","xml|ROOT/CONDITIONS/CONDITION/");
?>
Hi,
This is all down to how the data is being viewed. What's happening is that the the HTML document you are generating is not in the same character set as the data in your XML feed.
To fix this, all you need to do is issue a Content-Type header to specify the correct character set, and if your data is displayed correctly on this website then it is almost certainly UTF-8. Simply add the following line of code right at the top of your script - it must appear before any output is generated:
header("Content-Type: text/html;charset=utf-8");
...so including this fix into the code you posted above:
<?php
header("Content-Type: text/html;charset=utf-8");
require("MagicParser.php");
function myRecordHandler($record)
{
// This is where you write your code to process each record, such as loading a database
// You can display the record contents using PHP's internal print_r() function:
print_r($record);
// The following code will print out each field in your sample data:
print $record["CONDITION"];
}
$data = ""; // string variable contianing the data to parse
MagicParser_parse("string://".$data,"myRecordHandler","xml|ROOT/CONDITIONS/CONDITION/");
?>
That should do the trick!
Cheers,
David.