PHP - Function to replace nth occurence of a string without preg_match or preg_replace. In both 5.6 and 7.0 -- 2

I need a PHP function that can to a str_replace on specified occurrence of the needle in the haystack.

So for example

function replace_nth(find, replace, haystack, position).

function replace_nth('the', 'a', 'the angry man jumped over the gate and ate the sandwich', 2) {


should return "the angry man jumped over a gate and ate the sandwich".

the function shouldn't use any preg_match or preg_replace functions. It should also not rely on any strlen() function.

I need a version that works in PHP 5.6 and a version that works in PHP7 (if there is a better one that is using PHP 7 functions.


Taidot: PHP

Näytä lisää: php function location, php multi byte cut string, php function convert http links, php function validate post, web server php function, php extract phone number string, php function keywords extract, php function number format bilion milion, active directory php function, php function convert url html link, php function convert links href, php function match data, https scribie com freelance transcription rc 1 b 1 5 1 2 8 0 eb 5 0 e 8 0 0 1 d 3 8 fa 2 cd 6 bf 5 3 e 0 2 eb 1 2 0 c 8, developer in php function, freelance 5 6 7 8 mei 2016, joomla fatal error call to a member function get document on null in * plugins system sef sef php on line 36, pecl oci8 requires php version 7.0 0 installed version is 5.6 19 0 deb8u1, Write a public class method chopMiddle that accepts a String parameter with 5 integers in it separated by commas (e.g. “1,2,3,

Tietoa työnantajasta:
( 21 arvostelua ) Yonkers, United States

Projektin tunnus: #23942879

Myönnetty käyttäjälle:


Hello, ⭐⭐⭐⭐⭐ i am interested in this project , i can do this php function easily i can begin now waiting your answer on chat Regards ⭐⭐⭐⭐⭐

$29 USD 1 päivässä
(29 Arvostelua)

5 freelanceria on tarjonnut keskimäärin 32$ tähän työhön


How are you? I have gone through your requirements and I can do this task. Because I am expert. I can assure you of a complete professional work in a given timeline. Please share the complete detail of your requireme Lisää

$60 USD 7 päivässä
(1 arvostelu)

Hi, as a well-experienced PHP expert, I can do this perfectly as well as you want. I had ever worked on so many web projects using php frameworks. I have full experiences with html5, css3, bootstrap4, javascript, and m Lisää

$20 USD 7 päivässä
(4 arvostelua)

Hi, Nice to meet you! I am very interesting your project and I am confident of I can help your job. I am confident of this project as I'm a professional php expert with over 7 years of experience. Seems to be an intere Lisää

$30 USD 1 päivässä
(1 arvostelu)

Dear Client I have read your description very carefully and I am sure that can complete your project perfectly in short time. The Honest and Hard Work is different than other freelancers. I am a Web Developer and have Lisää

$20 USD 7 päivässä
(1 arvostelu)