yeah ok, so I need a delimiter to make the explode function on a string work, but what I'm trying to do is make an array filled with each character of the data contained in a file. I've tried something like

$dirToList = "./";
$handle = opendir("$dirToList");
while ($entry = readdir($handle)) {
	if (!is_dir($dirToList."/".$entry)) {
		$currentFile = fopen($entry, 'r') ;
		$data= explode("", $currentFile);
		echo $data;
	}
}

but explode won't work on this ("" isn't a delimiter!). Is there another function I could use to break the file up into an array with each element a character of the file contents? Obviously it's just a string so there's no delimiter in it.

Cheers all!

    Well, if you have data in specific positions every time, use an fget() and loop through the file, calling out specific values with the substr() function. We use this at my company to process logs created by some of our applications.It's more difficult since you do not have a delimiter, but looping through the file this way will get it done.
    If you need it to be an array of each character, set up a second loop to run through every line. Use a variable as a counter and put it into the substr() function.

      You can access a character string as an array.

      $str = 'abcdefgh';
      
      for ($i=0; $i<strlen($str); $i++) {
         echo $str[$i] . '<br>';
      }
      
      

      This should give
      a
      b
      c
      d
      e
      f
      g
      h

      hth

        Maybe you should first read something from the file cause $currentFile is the handler and doesn't contain data itself.

          You might be able to use the split() function. Although that uses a delimiter also, I don't believe that you have to use it.

          split ('', $var);

          -Blake

            Wow, you guys are keen tonight! Thanks all, I'll let you know how I get on.

            D

              Write a Reply...