orugari
orugari

Reputation: 426

PHP replace next occurence after "string" found

I would like to know how to find and replace the next ; after command

command "bleh", 1234, 567;

to

command ("bleh", 1234, 567);

This way is important, because string between command and ; can be completly different. Thank you for your help!

Upvotes: 0

Views: 22

Answers (1)

nospor
nospor

Reputation: 4220

You can use regular expressions and preg_replace():

$v = 'command "bleh", 1234, 567;';

$v = preg_replace('/command (.*?);/', 'command (\\1);', $v);
echo $v;

Upvotes: 1

Related Questions