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!

Link to comment
Share on other sites

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";
	}
}

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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!

Link to comment
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.