note 74564 added to function.utf8-encode

From: Date: Tue, 17 Apr 2007 18:15:03 +0000
Subject: note 74564 added to function.utf8-encode
Groups: php.notes 
Request: Send a blank email to php-notes+get-125526@lists.php.net to get a copy of this message
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 -- https://master.php.net/note/delete/74564/integrated Del: useless -- https://master.php.net/note/delete/74564/useless Del: bad code -- https://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 -- https://master.php.net/note/delete/74564/in+docs Del: other reasons-- https://master.php.net/note/delete/74564 Reject -- https://master.php.net/note/reject/74564 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#125526) next »