regex help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • basement_addict@yahoo.com

    regex help

    I am trying to remove all the headers in a text file.

    I tried this preg_replace('/^.*\n/', '',$body) but it only removed the
    first one.



    start of document-> Content-Type: text/plain
    Content-Transfer-Encoding: 8bit
    X-Input-Content-Type: application/msword
    X-Translator-Status: translating


    remove up to here ->This is the body of the document asdfdsafasdf
    ....
    ....
    ....

  • John Dunlop

    #2
    Re: regex help

    basement_addict @yahoo.com:
    [color=blue]
    > I am trying to remove all the headers in a text file.
    >
    > I tried this preg_replace('/^.*\n/', '',$body) but it only removed the
    > first one.[/color]

    It matches up to the first line-feed character. You want it to match
    up to the first occurrence of two consecutive line-feeds (the first two
    consecutive carriage-return/line-feed pairs, \r\n\r\n, perhaps?).
    Remember the s modifier so that the dot matches any single line-feeds.

    HTH.

    --
    Jock

    Comment

    • Justin Koivisto

      #3
      Re: regex help

      basement_addict @yahoo.com wrote:[color=blue]
      > I am trying to remove all the headers in a text file.
      >
      > I tried this preg_replace('/^.*\n/', '',$body) but it only removed the
      > first one.
      >
      >
      >
      > start of document-> Content-Type: text/plain
      > Content-Transfer-Encoding: 8bit
      > X-Input-Content-Type: application/msword
      > X-Translator-Status: translating
      >
      >
      > remove up to here ->This is the body of the document asdfdsafasdf[/color]

      preg_replace('` ^.*(\n{2}|\r\n{ 2})`Us','',$bod y);

      --
      Justin Koivisto, ZCE - justin@koivi.co m

      Comment

      Working...