这个类可以查找和查看文本字符串之间的差异。 它有两个文本字符串和使用的差异算法来找出它们之间的差异,并返回一个列表的变化,来修补原来的字符串成为最后的字符串。 PHP 源码与演示: 源码出处演示出处 ?php/* *from:http://www.codepearl.com */require(
这个类可以查找和查看文本字符串之间的差异。
它有两个文本字符串和使用的差异算法来找出它们之间的差异,并返回一个列表的变化,来修补原来的字符串成为最后的字符串。 PHP
源码与演示:源码出处 演示出处

<?php /* *from:http://www.codepearl.com */ require('diff.php'); $before = IsSet($_POST['before']) ? $_POST['before'] : 'Some text before'; $after = IsSet($_POST['after']) ? $_POST['after'] : 'This is the text after'; $mode = (IsSet($_POST['mode']) ? $_POST['mode'] : 'w'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="en"> <head> <title>Test the Diff Object</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <style type="text/css"> * { font-family: sans-serif,arial,helvetica } </style> <body> <form method="POST" action="?"> <div><label for="before">Before</label><br> <textarea id="before" cols="80" rows="10" name="before"><?php echo HtmlSpecialChars($before); ?></textarea></div> <div><label for="after">After</label><br> <textarea id="after" cols="80" rows="10" name="after"><?php echo HtmlSpecialChars($after); ?></textarea></div> <div><input type="submit" name="compare" value="Compare"> by <select name="mode"> <option value="c"<?php if($mode === 'c') echo ' selected'; ?>>Character</option> <option value="w"<?php if($mode === 'w') echo ' selected'; ?>>Word</option> <option value="l"<?php if($mode === 'l') echo ' selected'; ?>>Line</option> </select></div> <?php if(IsSet($_POST['compare'])) { $diff = new diff_class; $difference = new stdClass; $difference->mode = $mode; if($diff->FormatDiffAsHtml($before, $after, $difference)) echo '<div>Difference<br><div style="border-style: solid; border-width: 1px">', $difference->html, '</div></div>'; else echo '<div>Error: ', HtmlSpecialChars($diff->error), '</div>'; } ?> </form> </body> </html>
<?php /* *from:http://www.codepearl.com */ /* {metadocument}<?xml version="1.0" encoding="ISO-8859-1" ?> <class> <package>http://www.codepearl.com</package> <version>@(#) $Id: diff.php,v 1.4 2013/11/06 21:19:07 mlemos Exp $</version> <copyright>Copyright ?(C) http://www.codepearl.com</copyright> <title>OAuth client</title> <author>Manuel Lemos</author> <authoraddress>http://www.codepearl.com</authoraddress> <documentation> <idiom>en</idiom> <purpose>.</purpose> <usage>.</usage> </documentation> {/metadocument} */ class diff_class { var $error = ''; var $insertedStyle = 'font-weight: bold'; var $deletedStyle = 'text-decoration: line-through'; Function SplitString($string, $separators, $end, &$positions) { $l = strlen($string); $split = array(); for($p = 0; $p < $l;) { $e = strcspn($string, $separators.$end, $p); $e += strspn($string, $separators, $p + $e); $split[] = substr($string, $p, $e); $positions[] = $p; $p += $e; if(strlen($end) && ($e = strspn($string, $end, $p))) { $split[] = substr($string, $p, $e); $positions[] = $p; $p += $e; } } $positions[] = $p; return $split; } /* {metadocument} <function> <name>Diff</name> <type>BOOLEAN</type> <documentation> <purpose>.</purpose> <usage>.</usage> </documentation> <argument> <name>before</name> <type>STRING</type> <documentation> <purpose>.</purpose> </documentation> </argument> <argument> <name>after</name> <type>STRING</type> <documentation> <purpose>.</purpose> </documentation> </argument> <argument> <name>difference</name> <type>HASH</type> <out /> <documentation> <purpose>.</purpose> </documentation> </argument> <do> {/metadocument} */ Function Diff($before, $after, &$difference) { $mode = (IsSet($difference->mode) ? $difference->mode : 'c'); switch($mode) { case 'c': $lb = strlen($before); $la = strlen($after); break; case 'w': $before = $this->SplitString($before, " \t", "\r\n", $posb); $lb = count($before); $after = $this->SplitString($after, " \t", "\r\n", $posa); $la = count($after); break; case 'l': $before = $this->SplitString($before, "\r\n", '', $posb); $lb = count($before); $after = $this->SplitString($after, "\r\n", '', $posa); $la = count($after); break; default: $this->error = $mode.' is not a supported more for getting the text differences'; return false; } $diff = array(); for($b = $a = 0; $b < $lb && $a < $la;) { for($pb = $b; $a < $la && $pb < $lb && $after[$a] === $before[$pb]; ++$a, ++$pb); if($pb !== $b) { $diff[] = array( 'change'=>'=', 'position'=>($mode === 'c' ? $b : $posb[$b]), 'length'=>($mode === 'c' ? $pb - $b : $posb[$pb] - $posb[$b]) ); $b = $pb; } if($b === $lb) break; for($pb = $b; $pb < $lb; ++$pb) { for($pa = $a ; $pa < $la && $after[$pa] !== $before[$pb]; ++$pa); if($pa !== $la) break; } if($pb !== $b) { $diff[] = array( 'change'=>'-', 'position'=>($mode === 'c' ? $b : $posb[$b]), 'length'=>($mode === 'c' ? $pb - $b : $posb[$pb] - $posb[$b]) ); $b = $pb; } if($pa !== $a) { $diff[] = array( 'change'=>'+', 'position'=>($mode === 'c' ? $a : $posa[$a]), 'length'=>($mode === 'c' ? $pa - $a : $posa[$pa] - $posa[$a]) ); $a = $pa; } } if($a < $la) { $diff[] = array( 'change'=>'+', 'position'=>($mode === 'c' ? $a : $posa[$a]), 'length'=>($mode === 'c' ? $la - $a : $posa[$la] - $posa[$a]) ); } $difference->difference = $diff; return true; } /* {metadocument} </do> </function> {/metadocument} */ Function FormatDiffAsHtml($before, $after, &$difference) { if(!$this->diff($before, $after, $difference)) { return false; } $html = ''; $insertedStyle = (strlen($this->insertedStyle) ? ' style="'.HtmlSpecialChars($this->insertedStyle).'"' : ''); $deletedStyle = (strlen($this->deletedStyle) ? ' style="'.HtmlSpecialChars($this->deletedStyle).'"' : ''); $td = count($difference->difference); for($d = 0; $d < $td; ++$d) { $diff = $difference->difference[$d]; switch($diff['change']) { case '=': $html .= nl2br(HtmlSpecialChars(substr($before, $diff['position'], $diff['length']))); break; case '-': $html .= '<del'.$deletedStyle.'>'.nl2br(HtmlSpecialChars(substr($before, $diff['position'], $diff['length']))).'</del>'; break; case '+': $html .= '<ins'.$insertedStyle.'>'.nl2br(HtmlSpecialChars(substr($after, $diff['position'], $diff['length']))).'</ins>'; break; default: $this->error = $diff['change'].' is not an expected difference change type'; return false; } } $difference->html = $html; return true; } }; /* {metadocument} </class> {/metadocument} */ ?>


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

SecList
SecLists는 최고의 보안 테스터의 동반자입니다. 보안 평가 시 자주 사용되는 다양한 유형의 목록을 한 곳에 모아 놓은 것입니다. SecLists는 보안 테스터에게 필요할 수 있는 모든 목록을 편리하게 제공하여 보안 테스트를 더욱 효율적이고 생산적으로 만드는 데 도움이 됩니다. 목록 유형에는 사용자 이름, 비밀번호, URL, 퍼징 페이로드, 민감한 데이터 패턴, 웹 셸 등이 포함됩니다. 테스터는 이 저장소를 새로운 테스트 시스템으로 간단히 가져올 수 있으며 필요한 모든 유형의 목록에 액세스할 수 있습니다.

PhpStorm 맥 버전
최신(2018.2.1) 전문 PHP 통합 개발 도구

WebStorm Mac 버전
유용한 JavaScript 개발 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는
