PHP-比较两个文件和不存在';不匹配
好的,所以我四处看看,什么也没找到。 我在我创建的一个网站上使用它,因为客户因为删除公司品牌和添加自己的品牌而臭名昭著 php文件中有以下检查,但我希望它能够输出不同的行(如果它们不相同)PHP-比较两个文件和不存在';不匹配,php,Php,好的,所以我四处看看,什么也没找到。 我在我创建的一个网站上使用它,因为客户因为删除公司品牌和添加自己的品牌而臭名昭著 php文件中有以下检查,但我希望它能够输出不同的行(如果它们不相同) $orgf = 'http://example.com/originalindex.php'; //Original File $curf = 'index.php'; //This File $safe = FALSE; $error = ""; if (file_get_contents($orgf) =
$orgf = 'http://example.com/originalindex.php'; //Original File
$curf = 'index.php'; //This File
$safe = FALSE;
$error = "";
if (file_get_contents($orgf) == file_get_contents($curf)) { $safe = TRUE; } else { $safe = FALSE; $error = $error."Original index.php file has been modified<br/>"; }
$orgf='1http://example.com/originalindex.php'; //原始文件
$curf='index.php'//这个文件
$safe=FALSE;
$error=“”;
if(file_get_contents($orgf)==file_get_contents($curf)){$safe=TRUE;}else{$safe=FALSE;$error=$error。“原始index.php文件已被修改
”;}
谢谢,Matt。您可以尝试类似的方法,不过最好使用正确的文件路径
$differences=array_diff( file( $orgf ), file( $curf ) );
$safe=( empty( $differences ) ) ? true : false;
/*Show the differences */
echo '<pre>',print_r( $differences, true ),'</pre>';
$differences=array_diff(文件($orgf),文件($curf));
$safe=(空($differences))?真:假;
/*显示差异*/
回显“”,打印($differences,true),“”;
因为这些是0索引数组,不同的行看起来是索引+1。我像这样集成了它,效果非常好。$orgf='';$curf='index.php';$safe=FALSE;$error=“”;如果(file_get_contents($orgf)==file_get_contents($curf)){$safe=TRUE;}否则{$safe=FALSE;$error=$error.“
原始index.php文件已被修改
”;foreach(数组_diff(file($orgf),file($curf))作为$child){$error=$error.$child.
“;$error=$error.
”;}无论如何,我可以让它也输出它发现的每个差异的行号。