php生成xml文件
这是一款我在做flash xml交互时,利用php生成xml并把生成的xml数据保存到一个指定xml文档里了,代码如下:
- function cleanstring($str){
- $str = rawurldecode($str);
- $badchars = array("<", ">", ".", "/", "?", "#", "*", "(", ")", "[", "]", "{", "}", "\", ",", "=", '"', "'", ":", ";", "^", "@", "~", "!", " ");
- $clean = "";
- for($i=0; $i<strlen($str); $i++){
- if(array_search($str[$i], $badchars) === false){
- $clean .= $str[$i];
- }
- }
- return $clean;
- }
- $name = rawurlencode($_post['fname']);
- $message = rawurlencode($_post['message']);
- $xml = '<drawing message="'.$message.'" fname="'.$name.'">';
- $xml .= $_post['xml'];
- $xml .="</drawing>";
- $t = time();
- //开源代码phpfensi.com
- $filename = 'data/'.'99999'.$t.'_'.cleanstring($name).'.xml';
- $file = fopen($filename, "w");
- fwrite($file, strips教程lashes($xml));
- fclose($file);
print "xml=".$xml; 这里生成xml我们用了很简单的方法就是利用php fopen 创建一个文档,并保存成xml格式的.