#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |