My first cut at extracting the code from a PHP file, for those who might be interested. No Parse::RecDescent, it's not gorgeous code, but it seems to work well so far.
#!/usr/bin/perl -w # Extract PHP code from an input stream. This after # # http://www.palfrader.org/phpindent/phpindent # # didn't really turn my crank. # # T. Alex Beamish, TAB Software -- 19 August 2002 # Version 2.0 -- original version couldn't handle more # then one open or close tag on a line. use strict; my $InsideCode = 0; while (<>) { # print "$.:$InsideCode:$_"; # Add a newline after the closing PHP tag, and add a # newline in front of an opening tag. This way we get # no more than one opening and one closing tagon each # line fragment. s/(\?>)/$1\x0a/g; s/(<\?php)/\x0a$1/g; my @Data = split ( "\n", $_ ); # OK, go through the remaining line fragments. foreach ( @Data ) { next if ( /^\s*$/ ); # Skip blank portions of a # line. # If we're inside an opening block, watch for the # closing block. if ( $InsideCode == 1 ) { if ( /^(.*)\?>/ ) { print "$1\n"; $InsideCode = 0; } else { print "$_\n"; } } else # Otherwise watch for the opening block. { if ( /<\?php(.*)\?>/ ) { print "$1\n"; } elsif ( /<\?php(.*)$/ ) { print "$1\n"; $InsideCode = 1; } } } }

--t. alex
but my friends call me T.


In reply to Re: Parsing a PHP web application by talexb
in thread Parsing a PHP web application by talexb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.