Jump to content

File IO and Formating


clanstyles

Recommended Posts

I have this code.

<?php
include("config.php");

//exec("du -s *", $output);
$output = file("data.php", "r");
$var = arraytostring($output);
//$newoutput = explode("\t", $var);
$newoutput = explode("\n\t", $var);
$date = date("mm/d/y");
for($a=0;$a < count($newoutput);$a += 2)
{
	if($a % 2)
	{
		$dir = $newoutput[$a];
		$size = $newoutput[$a+1];
		echo "Size: " . $size . "<br />";
		echo "Dir: " . $dir . "<br />";
	}
	else
	{
		$dir = $newoutput[$a+1];
		$size = $newoutput[$a];
		echo "Size: " . $size . "<br />";
		echo "Dir: " . $dir . "<br />";
	}

	//if(!is_file($dir))
		//mysql_query("INSERT INTO `serverInfo` ( `id` , `serverid` , `size` , `filename` , `timestamp` ) VALUES('null', '1', '$size', '$dir', '06/25/07')") or die(mysql_error());


}

function arraytostring($array)
{
    $count=count($array);
    foreach ($array as $key=>$value)
    {
        $x++;
        if (is_array($value))
        {
            if(substr($text,-1,1)==')')    $text .= ',';
            $text.='"'.$key.'"'."=>".arraytostring($value);
            continue;
        }
        $text.=$value;
        if ($count!=$x) $text.="\t";
    }


   	if(substr($text, -4, 4)=='),),')$text.='))';
    return $text;
}
?>

 

Whats happening is that It isan't seeing the difference between the [tab] spacing. its four spaces.

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/61409-file-io-and-formating/
Share on other sites

Fourspaces sucks you can try and convert all 4 spaces into tabs.

 

<?php
$var = str_replace("    ", "\t", $file); 
$newoutput = explode("\n\t", $var);
?>

 

But that is flawed in its own sense too. If you are expecting tabs but are getting 4 spaces, sounds like you need to fix the original file.

Link to comment
https://forums.phpfreaks.com/topic/61409-file-io-and-formating/#findComment-314167
Share on other sites

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.