Skip site navigation (1)Skip section navigation (2)
Date:      Sun,  7 Jun 2009 16:52:10 -0400 (EDT)
From:      vogelke+unix@pobox.com (Karl Vogel)
To:        freebsd-questions@FreeBSD.ORG
Subject:   Re: enclose code and testfile.
Message-ID:  <20090607205210.5A2AFBED4@kev.msw.wpafb.af.mil>
In-Reply-To: <20090607012158.GA14286@thought.org> (message from Gary Kline on Sat, 6 Jun 2009 18:22:00 -0700)
References:  <20090607012158.GA14286@thought.org>

next in thread | previous in thread | raw e-mail | index | archive | help
>> On Sat, 6 Jun 2009 18:22:00 -0700, 
>> Gary Kline <kline@thought.org> said:

G> I'm encloseing a brief C program that skips over php delimiters and a
G> 74-byte test file.  Am wondering if there is a better way.

   #!/usr/bin/perl -w
   # skip PHP stuff in a file

   use strict;
   my ($prev, $match);

   # slurp up the entire file.
   undef $/;
   $_ = <>;

   while (s/
             (.*?)         # get text that doesn't include delimiters...
             (<\?.*?\?>)   # ... plus text in ONE set of delimiters...
             //xsm)        # ... matching across multiple lines
   {
       $prev = $1;         # text before <?
       $match = $2;        # text inside <?...?>
       print "$prev";
   }

   print "$_\n";           # whatever's left over.
   exit(0);

-- 
Karl Vogel                      I don't speak for the USAF or my company

Programming is like sex:  one mistake and you have to
support for a lifetime.                                 --unknown



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20090607205210.5A2AFBED4>