B
B
Buripov2015-11-16 21:19:56
PHP
Buripov, 2015-11-16 21:19:56

How to select all words that come before the comma by skipping N number of words at the beginning of the sentence?

Only a person cannot accept the fact that someone has an advantage over him. Select all words up to a comma after the word topic, and skipping N number of words at the beginning, for example, a person cannot come to terms with that

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2015-11-16
@Buripov

$str = 'Лишь человек не может примириться с тем, что у кого-то есть преимущество перед ним.';
$N = 1;

if (preg_match('/(\b\w+\b\W+){'.$N.'}\b(.+),/u', $str, $match)) {
    echo $match[2];
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question