user3027056 user3027056 - 6 months ago 38
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);


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

echo strstr($string, 'ABC:');