我在优化 MySql 查询的搜索字符串时遇到了 PHP 函数的问题。
我需要通过搜索“the hobbit”来找到一个看起来像“hobbit, the”的条目。
我考虑过如果文章的搜索字符串中有尾随空格,则将其删除(在德国,我们有“der”、“die”和“das”)。
我的函数如下所示:
public function optimizeSearchString($searchString)
{
$articles = [
'der ',
'die ',
'das ',
'the '
];
foreach ($articles as $article) {
//only cut $article out of $searchString if its longer than the $article itself
if (strlen($searchString) > strlen($article) && strpos($searchString, $article)) {
$searchString = str_replace($article, '', $searchString);
break;
}
}
return $searchString;
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用...
也许使用正则表达式有更好的解决方案?
我在测试时遇到了一个问题:
我尝试使用 Laravel Mail::fake() 测试邮件的发送,如下所示:
/** @test */
public function an_activation_mail_gets_send_on_registration()
{
Mail::fake();
Mail::to('john@example.com')->send(new TestMail());
Mail::asserSent(TestMail::class);
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
Error : Call to undefined method Illuminate\Support\Testing\Fakes\MailFake::asserSent()
Run Code Online (Sandbox Code Playgroud)
在我看来,它与文档中的一样:https : //laravel.com/docs/master/mocking#mail-fake
任何人都知道解决方案吗?