php生成xml文件

这是一款我在做flash xml交互时,利用php生成xml并把生成的xml数据保存到一个指定xml文档里了,代码如下:

  1. function cleanstring($str){
  2. $str = rawurldecode($str);
  3. $badchars = array("<", ">", ".", "/", "?", "#", "*", "(", ")", "[", "]", "{", "}", "\", ",", "=", '"', "'", ":", ";", "^", "@", "~", "!", " ");
  4. $clean = "";
  5. for($i=0; $i<strlen($str); $i++){
  6. if(array_search($str[$i], $badchars) === false){
  7. $clean .= $str[$i];
  8. }
  9. }
  10. return $clean;
  11. }
  12. $name = rawurlencode($_post['fname']);
  13. $message = rawurlencode($_post['message']);
  14. $xml = '<drawing message="'.$message.'" fname="'.$name.'">';
  15. $xml .= $_post['xml'];
  16. $xml .="</drawing>";
  17. $t = time();
  18. //开源代码phpfensi.com
  19. $filename = 'data/'.'99999'.$t.'_'.cleanstring($name).'.xml';
  20. $file = fopen($filename, "w");
  21. fwrite($file, strips教程lashes($xml));
  22. fclose($file);

print "xml=".$xml; 这里生成xml我们用了很简单的方法就是利用php fopen 创建一个文档,并保存成xml格式的.