I want to insert a text string inside another one after certain number or words. For example:
$text_to_add = "#Some Text to Add#";
$text_original = "This is the complete text in which I want to insert the other text";
$number_words = 7; // Variable that will define after how many words I must put $text_to_add
I want to get the following result when I print $text_original:
This is the complete text in which #Some Text to Add# I want to insert the other text
I can use this function http://php.net/manual/en/function.str-word-count.php to get an array of words, go through it building a new string with the $text_to_add inserted, but I wondering if there is a better way to accomplish this, since some of my $text_original texts are very long.
Thanks in advance.
Try this: