rasmusrosengren / string-diff
一个类,用于提取格式相同但只有细微差别的字符串中的变量
1.0.0
2016-08-07 21:38 UTC
Requires
- php: 5.6.*
This package is not auto-updated.
Last update: 2024-09-15 02:02:49 UTC
README
StringDiff 是一个小插件,允许轻松操作格式相似但位置有微小差异的字符串。
使用方法
new StringDiff
$stringd = new StringDiff;
$test_array = [
"Your Cooldown Reduction cap is increased to 41% and you gain 1% Cooldown Reduction",
"Your Cooldown Reduction cap is increased to 42% and you gain 2% Cooldown Reduction",
"Your Cooldown Reduction cap is increased to 43% and you gain 3% Cooldown Reduction",
"Your Cooldown Reduction cap is increased to 44% and you gain 4% Cooldown Reduction",
"Your Cooldown Reduction cap is increased to 45% and you gain 5% Cooldown Reduction",
];
$stringd->run($test_array);
foreach($stringd->getArgs() as $arg)
{
echo vsprintf($stringd->getUnformattedString(), $arg) . '<br>';
}
run(array $arr)
方法处理数据数组,并输出未格式化的字符串和一个参数数组,未格式化的字符串包含 %s
,这些占位符随后通过使用 vsprintf($unformatted string, array $args)
进行替换。
getUnformattedString()
方法返回包含 %s
占位符的未格式化字符串。
getArgs()
返回一个参数数组,格式如下
0 => [
0 => 41
1 => 1
],
1 => [
0 => 42,
1 => 2
]
...