samedi 9 janvier 2016

How can I style the display of an array resulted through var_dump

Vote count: 0

I've a code to search files in a directory. I'm using the code var_dump($search->foundFiles) to display the results in a webpage, but I can't figure out how to find te correct code for proper display and the the results are URL.

The result of var_dump($search->foundFiles) is:

Array ( [0] => archivednews/2016-01-08 22h30 Zika Virus archived news.html [1] => archivednews/2016-01-07 22h30 Zika Virus archived news.html )

But I would like to have it displayed in a list with clickable links to the found files like this:

  • 2016-01-05 22h30 Zika Virus archived news.html
  • 2016-01-04 22h30 Zika Virus archived news.html
  • 2016-01-08 22h30 Zika Virus archived news.html

Please help

This is the complete code:

    <?php
    class searchFileContents{
     var $dir_name = '';//The directory to search
     var $search_phrase = '';//The phrase to search in the file contents
     var $allowed_file_types = array('php','phps');//The file types that are searched
     var $foundFiles;//Files that contain the search phrase will be stored here
     var $myfiles;

function search($directory, $search_phrase){
    $this->dir_name = $directory;
    $this->search_phrase = $search_phrase;

    $this->myfiles = $this->GetDirContents($this->dir_name);
    $this->foundFiles = array();

    if ( empty($this->search_phrase) ) die('Empty search phrase');
    if ( empty($this->dir_name) ) die('You must select a directory to search');

    foreach ( $this->myfiles as $f ){
        if ( in_array(array_pop(explode ( '.', $f )),  $this->allowed_file_types) ){
            $contents = file_get_contents($f);
            if ( strpos($contents, $this->search_phrase) !== false )
                $this->foundFiles [] = $f;
        }
    }
    return $this->foundFiles;
}

function GetDirContents($dir){
   if (!is_dir($dir)){die ("Function GetDirContents: Problem reading : $dir!");}
   if ($root=@opendir($dir)){
       while ($file=readdir($root)){
           if($file=="." || $file==".."){continue;}
           if(is_dir($dir."/".$file)){
               $files=array_merge($files,$this->GetDirContents($dir."/".$file));
           }else{
           $files[]=$dir."/".$file;
           }
       }
   }
   return $files;
}

}

    //Example :

    $search = new searchFileContents;
    $search->search('E:/htdocs/AccessClass', 'class');
    var_dump($search->foundFiles);

?>

asked 1 min ago

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at http://ift.tt/jcXqJW.



How can I style the display of an array resulted through var_dump

Aucun commentaire:

Enregistrer un commentaire