Jump to content

[SOLVED] how to print or echo data using custom function


mallard

Recommended Posts

I'm trying to understand how you can print out data using a custom function. Say I have this line of code:

function myFunction($parameter) {
etc...

What I wanna do is take the data that the rest of the script extracts from a directory of files and sort it and print it out to the browser. Now if I use print_r like this:

print_r(myFunction('./'));

I don't understand what './' does there actually (if someone could explain that really quick that would be great) but that prints multiple arrays of data out to the screen and I can see everything that I want IS there. But how do you echo or print the arrays of data out so that you can put the data into a table or something like that?

 

Thanks for any help!

Okay... here's the whole script that I'm using:

<?php

function dataArray($sz_pathToFiles) {
  
  $ar_seq = array(255,255,1,0,7,0);
  $ar_tabFiles = array();
  $b_lastWasNewline = false;
  $b_seqActive = false;
  
  
  if(preg_match('/\/$/',$sz_pathToFiles) == 0) {
    $sz_pathToFiles .= "/";
  }


  foreach(glob($sz_pathToFiles . "tabs/*.ext") as $file) {

    $n = 0;
    $b_found = false;
    $b_lastWasNewline = false;
    $sz_out = "";
    $n_found = -1;
    $n_seqCount = 0;
    $n_char = 0;
    $n_linesExtracted = 0;
    $ar_tabFiles[basename($file)] = array();
  
    $fileData = file_get_contents($file);
    $fileData = bin2hex($fileData);
  
    while($n < strlen($fileData) && !$b_found && $n_linesExtracted < 4) {
  

      $n_char = substr($fileData,$n,2);
      $n_char = base_convert($n_char,16,10);

      if($n_char > 31 && $n_char < 127) {
        if($b_lastWasNewline && ( preg_match('/[a-zA-Z0-9]/',chr($n_char)) == 0 ) ) {
          $b_lastWasNewline = false;
        }
        else {
          $sz_out .= chr($n_char);
          $b_lastWasNewline = false;
        }
      }
      else {

        if(!$b_lastWasNewline) {
          $ar_tabFiles[basename($file)][$n_linesExtracted] = $sz_out;
          $sz_out = "";
          $b_lastWasNewline = true;
          ++$n_linesExtracted;
        }
      }
  

      if($n_char == $ar_seq[$n_seqCount]) {
        $n_seqCount += 1;
        $b_seqActive = true;
      }
      elseif($b_seqActive) {
        $n_seqCount = 0;
        $b_seqActive = false;
      }
  
      $n += 2;
  
      if($n_seqCount == sizeof($ar_seq)) {
        $b_found = true;
      }
  
    }
  
  }
  
  return $ar_tabFiles;
}

print_r(dataArray('./'));



?>

When I do that print_r I see all of the arrays of stuff that I want but I don't understand how to echo or print the stuff from that function dataArray. Like, is there way to echo the array content out individually so that I can sort it out in a table?

Hmm... I've tried that and it doesn't display anything on the screen. Unless I'm not putting the right thing inside the parenthesis. It's a shame that I can't figure this out 'cause the function is extracting the exact data that I want. I just don't understand how to print it out to the screen and work with it so like each file will be on a new line and even sort the data and stuff.

 

Any other thoughts?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.