#!/usr/bin/php 
<?
/* Join all command line arguments into one string */
$str join(" ",array_slice($argv,1));

/* Display the string so we know what we are matching */
print "\n\nThe input string to match is:\n$str\n--------------------\n";

/* The regular expression itself */
preg_match_all("{
(\w+)\s*=\s*                 #the parameter name, captured to $1, followed by an equals sign

[\"](                         #opening quote of value, begin capturing $2

[^\"\\\\]*                    #capture up to the first escape character

(?:\\\\.[^\"\\\\]*)*        #capture the backslash, the char to escape,
                            #and anything up to the next backslash; -- and do this any # of times
                            
)[\"]                        #end of $2, closing quote
}x"
$str$matchesPREG_SET_ORDER);

/* Print out any name/value pairs that are found. i.e. title="\"The Title\"" */

if ($matches) {
    print 
"The name and attribute pairs are:";
    for (
$i=0,$n=sizeof($matches);$i<$n;$i++) {
        print 
"\n".$matches[$i][1]." => ".stripslashes($matches[$i][2]);
    }
}

print 
"\n\n";