-1

I have in my content a few paragraphs and want to cut everything before when I find for example: This is a comment statement

I tried with str_replace() but this is not possible with this method and with preg_replace but on every validation my content stay untouched.

Is there any better way to do so?

1
  • 1
    Take a look at strrpos and substr
    – Plancke
    Jun 13, 2019 at 6:06

1 Answer 1

0

str_replace will not work in you case. Try preg_replace and remove the first matching pattern -

preg_replace('/.+?(?=This is a comment statement)/', '', $your_string, 1)

Detailed explanantion

1
  • it works with one-line string, can it be implemented for multiline strings? Jun 13, 2019 at 7:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.