Using sed to remove a block of text

前端 未结 3 1868
臣服心动
臣服心动 2021-02-05 02:09

I have a block of text that looks like this:

    
... a bunch of stuff 
    

I\'d like to remov

3条回答
  •  日久生厌
    2021-02-05 02:41

    These days I am using the /s modifier to do this. I noticed no one mentioned that. I use markup with is free of spaces too like

    {bof-nf} ... a bunch of stuff {eof-nf}

    So for example, to remove this block, use

    $newcontent = preg_replace("/\{bof-nf\}(.*)\{eof-nf\}\\n/s", "", $newcontent);

    To keep the block but remove the tags, use

    $newcontent = preg_replace("/\{bof-nf\}.*\\n/", "", $newcontent); $newcontent = preg_replace("/\{eof-nf\}.*\\n/", "", $newcontent);

提交回复
热议问题