I
I
Ivan2016-09-17 06:23:23
PHP
Ivan, 2016-09-17 06:23:23

Replacing the Nth element of a string in PHP - how to implement it?

There is a large text in which the same words can occur, for example, the word "begin"
You need to replace a certain Nth occurrence of this word (for example, the 5th) with the word "end".
How to replace exactly the Nth occurrence of a substring in a string in PHP ???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2016-09-17
@iwqn

find the position of the desired occurrence and replace with substr_replace .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question