Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.