Issue
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?
Solution
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)
Answered By - Sougata Bose Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.