@ 2016-05-18T12:57:50Z <?php
$matches = [
[
'insult' => [
'text' => 'You fight like a Dairy Farmer!',
'maxDistance' => 15,
],
'response' => [
'text' => 'How appropriate! You fight like a cow!',
'maxDistance' => 20,
],
],
[
'insult' => [
'text' => 'This is the END for you, you gutter crawling cur!',
'maxDistance' => 32,
],
'response' => [
'text' => 'And I\'ve got a little TIP for you, get the POINT?',
'maxDistance' => 25,
],
],
];
$search = "This is the end for you, gutter-crawling cur!";
$closestSet = null;
$closestScore = 0;
foreach ($matches as $set) {
$score = similar_text($search, $set['insult']['text']);
var_dump($score);
if ($score > $closestScore) {
$closestScore = $score;
$closestSet = $set;
}
}
echo "---", PHP_EOL;
var_dump($search, $closestScore, $closestSet);
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 5.5.0 - 5.5.35 , 5.6.0 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 , 7.2.6 - 7.2.33 , 7.3.16 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 , 8.1.0 - 8.1.33 , 8.2.0 - 8.2.29 , 8.3.0 - 8.3.26 , 8.4.1 - 8.4.13 int(10)
int(41)
---
string(45) "This is the end for you, gutter-crawling cur!"
int(41)
array(2) {
["insult"]=>
array(2) {
["text"]=>
string(49) "This is the END for you, you gutter crawling cur!"
["maxDistance"]=>
int(32)
}
["response"]=>
array(2) {
["text"]=>
string(49) "And I've got a little TIP for you, get the POINT?"
["maxDistance"]=>
int(25)
}
}
preferences:dark mode live preview ace vim emacs key bindings
103.43 ms | 409 KiB | 5 Q