user3027056 user3027056 - 1 year ago 63
PHP Question

preg_replace() everything before a match to blank only once

Variable value:

1000+ lines of not required text

ABC: Required text.

ABC: More Required text.

Goal is to replace everything before the first "ABC:" i.e the 1000+ lines of not required text to blank. As far as I read, I need to use

with the limit parameter to 1.

How do I go about doing this?

preg_replace("/.*/ABC:" , "ABC:", $string, 1);

Answer Source

You don't need preg_replace() when you can use strstr to do this.

echo strstr($string, 'ABC:');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download