-1

例如我有以下段落

当您准备好完成采访时,请单击采访我。不用担心,在您参加完整的面试之前,您将有机会练习。工作截止日期为 2030 年 12 月 30 日,因此请确保届时您已回复我们。感谢您申请。

我需要删除包含“2030 年 12 月 30 日”的整个句子。

请提出解决方案。

4

3 回答 3

2

您可以通过多种方式执行此操作,但我只会使用此方法:

  1. 爆炸你的弦.
  2. 仔细检查你的价值观,只保留那些December 30, 2030不存在的价值观。

.但是如果你在一个句子里面有a ,这就会有问题。在这种情况下,您将需要考虑一种不同的方式来将您的句子彼此分开。

$string = "When you are ready to complete the interview, click Interview me . Don't worry, you will have a chance to practice before you take the full interview. The job closing date is December 30, 2030 so make sure you have your response back to us by then. Thanks for applying.";
$search = "December 30, 2030";

$sentences = explode( '.', $string );

$new_string = '';
foreach ( $sentences as $sentece )
{
    if ( !strpos( $sentece, $search ) )
        $new_string .= $sentece . '.';
}

输出:

When you are ready to complete the interview, click Interview me . Don't worry, you will have a chance to practice before you take the full interview. Thanks for applying.
于 2012-12-14T07:30:35.550 回答
1

为什么不先把它分解成句子呢?然后对每个句子运行测试,并且仅在测试告诉您应该包含它时才将其包含在输出中?

于 2012-12-14T07:31:03.090 回答
-1

一个简单的解决方案是替换

str_replace('December 30, 2030', '', 'When you are ready to complete the interview, click Interview me . Don't worry, you will have a chance to practice before you take the full interview. The job closing date is December 30, 2030 so make sure you have your response back to us by then. Thanks for applying');

这样您也可以使用当前日期更改它:

str_replace('December 30, 2030', date('l jS \of F Y h:i:s A'), 'When you are ready to complete the interview, click Interview me . Don't worry, you will have a chance to practice before you take the full interview. The job closing date is December 30, 2030 so make sure you have your response back to us by then. Thanks for applying');
于 2012-12-14T07:30:26.867 回答