1

I've some text:

Reply: Alter pot water it your pot. Please Reply this text. If you Reply this text you get some money. Please Reply

So i want to replace first Reply text with Hi. Not another Reply text.

I know i can do this with str_replace() function with php. But it replace all Reply text with Hi. But i need to replace first Reply text.

how do i do this with php?

1 Answer 1

1

The 4th parameter of preg_replace() is the max replacement to be done. Set it to 1.

$str = preg_replace('/reply/i', 'Hi', $str, 1);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.