creating utf-8 xml files:
this is something that has wasted a lot of my time, I hope
this will spare you the headaches:
my method consists of creating an xml template that will
look like this (this is probably optional, I'm sure you can
use good ol' print or echo statements):
xml_tpl.php
<?php
header("Content-Type:
text/html;charset=ISO-8859-1");
print "<?xml version="1.0"
encoding="UTF-8" ?>n";
$names=array('jack','bob','vanessa','catherine','valerie');
?>
<parent>
<?php foreach($names as $name) {?>
<child name="<?php print $name?>" />
<?php } ?>
</parent>
?>
from a function or a method I include the previous template
and trap the outputted content in an output buffer. The
buffured content is then inserted into a file:
<?php
function create_xml(){
ob_start();
include "xml_php.php";
$trapped_content=ob_get_contents();
ob_end_clean();
$file_path= "./somefile.xml";
$file_handle=fopen($somefile,'w');
fwrite($file_handle,utf8_encode($trapped_content));
}
?>
Some side notes:
- note that the utf8_encode function goes inside the
fwrite() function.
- when troubleshooting, make sure to transfer text file (xml
included) and scripts in ascii mode when using ftp. For some
unknown reason my ftp client did not have xml set as an
ascii transfer candidate and was automatically tranfering
them in binary. That little "feature" ended up
costing me hours of frustration, as the encoding information
would just "vanish" between transfer and I kept
scratching my head as to why manually created utf8 files
were not behaving as they should.
----
Server IP: 66.207.199.35
Probable Submitter: 69.70.24.116
----
Manual Page -- http://www.php.net/manual/en/function.utf8-encode.php
Edit -- https://master
.php.net/note/edit/74564
Del: integrated -- h
ttps://master.php.net/note/delete/74564/integrated
Del: useless -- http
s://master.php.net/note/delete/74564/useless
Del: bad code -- htt
ps://master.php.net/note/delete/74564/bad+code
Del: spam -- https:/
/master.php.net/note/delete/74564/spam
Del: non-english --
https://master.php.net/note/delete/74564/non-english
Del: in docs -- http
s://master.php.net/note/delete/74564/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/74564
Reject -- https://mast
er.php.net/note/reject/74564
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|