mallard Posted January 9, 2009 Share Posted January 9, 2009 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! Quote Link to comment https://forums.phpfreaks.com/topic/140098-solved-how-to-print-or-echo-data-using-custom-function/ Share on other sites More sharing options...
kenrbnsn Posted January 9, 2009 Share Posted January 9, 2009 Please show us the code for myFunction. Ken Quote Link to comment https://forums.phpfreaks.com/topic/140098-solved-how-to-print-or-echo-data-using-custom-function/#findComment-733012 Share on other sites More sharing options...
mallard Posted January 9, 2009 Author Share Posted January 9, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140098-solved-how-to-print-or-echo-data-using-custom-function/#findComment-733022 Share on other sites More sharing options...
9three Posted January 9, 2009 Share Posted January 9, 2009 Looks like they are doing that for you already. Do the following: <?php dataArray(); ?> Between the parenthesis you need to put the path where your files are stored. Quote Link to comment https://forums.phpfreaks.com/topic/140098-solved-how-to-print-or-echo-data-using-custom-function/#findComment-733038 Share on other sites More sharing options...
mallard Posted January 9, 2009 Author Share Posted January 9, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/140098-solved-how-to-print-or-echo-data-using-custom-function/#findComment-733044 Share on other sites More sharing options...
zssz Posted January 9, 2009 Share Posted January 9, 2009 Looks like a foreach would be handy http://us3.php.net/foreach Quote Link to comment https://forums.phpfreaks.com/topic/140098-solved-how-to-print-or-echo-data-using-custom-function/#findComment-733048 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.