php Getting files list &(ampersand) character error -


i have code getting files list in php, if file name contain & character doesn't display file. here's code:

ps. i'm not php programmer , don't know error. appreciated in advance.

<?php include_once('config.inc.php'); $current_dir = 'root'; if(array_key_exists('directory',$_post)) { $current_dir = $_post['directory']; }  // creating new xml using domdocument  $file_list = new domdocument('1.0');  $xml_root = $file_list->createelement('filelist');  $xml_root = $file_list->appendchild($xml_root);   // setting 'currentpath' attribute of xml  $current_path = $file_list->createattribute('currentpath');  $current_path->appendchild($file_list->createtextnode($current_dir));  $xml_root->appendchild($current_path);   // replacing word 'root' real root path  $current_dir = substr_replace($current_dir, $root, 0, 4);   $di = new directoryiterator($current_dir);   // creating xml using directoryiterator  while($di->valid())  { if(false == $di->isdot()) {     if($di->isdir() && true != in_array($di->getbasename(),$h_folders))     {         $fl_node = $file_list->createelement('dir');         $xml_root->appendchild($fl_node);     }else if($di->isfile() && true !== in_array($di->getbasename(),$h_files)              &&  true !== in_array(get_ext($di->getbasename()),$h_types))     {         $fl_node = $file_list->createelement('file');         $xml_root->appendchild($fl_node);     }else      {         $di->next();             continue;     }     $name = $file_list->createelement('name',$di->getbasename());     $fl_node->appendchild($name);     $path = substr_replace($di->getrealpath(), 'root', 0, strlen($root));     $path_node = $file_list->createelement('path', $path);     $fl_node->appendchild($path_node);     $di->next(); }else $di->next(); }  function get_ext($filename) { $exp = '/^(.+)\./'; return preg_replace($exp,'',$filename); }   // returning xml flash.  echo $file_list->savexml();  ?> 

the & character used in html write entities.

if want display arbitrary text in html, need escape calling htmlentities().


Comments