Are there any libraries (3rd party or built-in) in PHP
to calculate text diffs?
php
diff
Asked 2 Years ago Answers: 5 Viewed 59 times
Answers
4
Could you not compare the time stamps instead?
$now = new DateTime('now');
$diff = $date->getTimestamp() - $now->getTimestamp()
Tuesday, December 20, 2022
1
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
.
Sunday, December 25, 2022
3
Here's a nice little function that will add up any number of times passed in an array:-
function addTimes(Array $times)
{
$total = 0;
foreach($times as $time){
list($hours, $minutes, $seconds) = explode(':', $time);
$hour = (int)$hours + ((int)$minutes/60) + ((int)$seconds/3600);
$total += $hour;
}
$h = floor($total);
$total -= $h;
$m = floor($total * 60);
$total -= $m/60;
$s = floor($total * 3600);
return "$h:$m:$s";
}
Use it like this:-
$times = array('12:39:25', '08:22:10', '11:08:50', '07:33:05',);
var_dump(addTimes($times));
Output:-
string '39:43:30' (length=8)
Monday, August 29, 2022
3
You should be checking the user agent string, most well behaved search bots will report themselves as such.
Google's spider for example.
Wednesday, September 14, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
php
diff
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.