Answer the question
In order to leave comments, you need to log in
How to insert a couple of words into a sentence, knowing which word to insert after?
It is common for each of us to love someone, you need to add words not after 3 words, that is, us after 4 words (typically), a simple check if word == will not do us, there can be any sentence, you need to write after a certain word number
Answer the question
In order to leave comments, you need to log in
The main thing here is to understand the logic of how to break up what a "word" is. The easiest way to split by spaces and paste where necessary ... More or less universal option:
<?php
function func ($text, $num, $addText) {
$explode = explode(' ', $text, $num + 1);
$last = array_pop($explode);
array_push($explode, $addText, $last);
return implode(' ', $explode);
}
$result = func('Каждому из нас свойственно любить кого-нибудь', 4, 'Привет!');
?>
The question is a stream of consciousness. But splitting the string by spaces and then gluing the resulting pieces together is probably quite a working option.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question