Asked  7 Months ago    Answers:  5   Viewed   31 times

Are there any libraries (3rd party or built-in) in PHP to calculate text diffs?

 Answers

98

What sort of diffs? File diffs? There is array_diff() which acts on arrays. Then there is also xdiff, which "enables you to create and apply patch files containing differences between different revisions of files.". The latter acts on files or strings.

Edit: I should add xdiff doesn't appear to be out in a release yet. You have to build from source to use it.

Wednesday, March 31, 2021
 
Classified
answered 7 Months ago
73

self::, parent:: and static:: are special cases. They always act as if you'd do a non-static call and support also static method calls without throwing an E_STRICT.

You will only have problems when you use the class' names instead of those relative identifiers.

So what will work is:

class x { public function n() { echo "n"; } }
class y extends x { public function f() { parent::n(); } }
$o = new y;
$o->f();

and

class x { public static function n() { echo "n"; } }
class y extends x { public function f() { parent::n(); } }
$o = new y;
$o->f();

and

class x { public static $prop = "n"; }
class y extends x { public function f() { echo parent::$prop; } }
$o = new y;
$o->f();

But what won't work is:

class x { public $prop = "n"; }
class y extends x { public function f() { echo parent::prop; } } // or something similar
$o = new y;
$o->f();

You still have to address properties explicitly with $this.

Wednesday, March 31, 2021
 
Floris
answered 7 Months ago
86
date_default_timezone_set('Europe/Warsaw');
$from = strtotime('2013-11-01');
$today = time();
$difference = $today - $from;
echo floor($difference / 86400);  // (60 * 60 * 24)

or

date_default_timezone_set('Europe/Warsaw');
$datetime1 = new DateTime('2013-11-01');
$datetime2 = new DateTime('2013-11-15');
$interval = $datetime1->diff($datetime2);
echo $interval->format('%a');
Wednesday, March 31, 2021
 
Sidarta
answered 7 Months ago
38

Without loop using range() & array_map() :

EDIT: a little mistake, you have to jump 86400, because 1 day = 86400 seconds, so the code should be fine now :)

    $st_date = '2012-07-20';
    $ed_date = '2012-07-27';
    $dates = range(strtotime($st_date), strtotime($ed_date),86400);
    $range_of_dates = array_map("toDate", $dates);
    print_r($range_of_dates);
    function toDate($x){return date('Y-m-d', $x);}

?>
Wednesday, March 31, 2021
 
TecHunter
answered 7 Months ago
14

You should be checking the user agent string, most well behaved search bots will report themselves as such.

Google's spider for example.

Saturday, May 29, 2021
 
Ultimater
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :