Shibbir
Shibbir

Reputation: 91

Php string replace issue

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?

Upvotes: 1

Views: 62

Answers (1)

flowfree
flowfree

Reputation: 16462

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);

Upvotes: 1

Related Questions