Jump to content

[SOLVED] array_diff ouput reverse


homer.favenir

Recommended Posts

array_intersect()? Looking in the manual at the function you know about (e.g. http://www.php.net/array_diff) will help you find similar functions by looking under the section 'See Also'.

 

thanks, it works, but the it didnt extract the last line.

e.g. only 3 lines are the same on both array1 and array2, only 2 lines were return and the last line

isnt....

 

any advice...

 

thanks!

function intersect($str1, $str2)
{
	$count = 0;
	$dir = 'C:\Documents and Settings\All Users\Desktop\portfoliocompare\\';
	$file = $_POST['newFile'];
	$file = $dir . $file . ".txt";
	if(file_exists($file))
		{?>
			<table border=0>
			<tr>
			<td>
			<h2><font color="#FF0000">Warning! </font>File Already Exist. Pls Rename</h2>
			</td>
			</tr>
			</table>
		<?php }else{

	$file = trim($file);
	$file = fopen($file, 'w');
	$diff = array_intersect($str1, $str2);

	foreach($diff as $key => $line)
	{
		echo $line . "<br>";
		fwrite($file, $line);
		$count++;
	}
	echo $count . " " . "Records found";
	}
}

How about narrowing down the problem? I've no idea what the above code does and i've also no idea what your previous discription meant.

 

How about providing sample arrays of $str1, $str2 and what iis in $diff. Im assuming that's where the problem lies?

I already know the cause,

the first txt file to compare has extra last line (but no characters), the second txt file to compare has no extra last line. that is why it didnt extracted the last line.

 

how to ignore if the txt file has an extra last line or it hasnt?

 

thanks!

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.