如何剪切句子前的内容?
How to cut content before sentence?
我的内容中有几段,想在我找到之前删除所有内容,例如:这是评论声明
我尝试使用 str_replace()
,但使用此方法和 preg_replace
是不可能的,但在每次验证时我的内容都保持不变。
有没有更好的方法呢?
str_replace
不适用于您的情况。尝试 preg_replace
并删除第一个匹配模式 -
preg_replace('/.+?(?=This is a comment statement)/', '', $your_string, 1)
Detailed explanantion
我的内容中有几段,想在我找到之前删除所有内容,例如:这是评论声明
我尝试使用 str_replace()
,但使用此方法和 preg_replace
是不可能的,但在每次验证时我的内容都保持不变。
有没有更好的方法呢?
str_replace
不适用于您的情况。尝试 preg_replace
并删除第一个匹配模式 -
preg_replace('/.+?(?=This is a comment statement)/', '', $your_string, 1)
Detailed explanantion