-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?

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87
Marco Tesini
  • 13
  • 1
  • 5

1 Answers1

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

Sougata Bose
  • 31,517
  • 8
  • 49
  • 87