Forum Moderators: coopster

Message Too Old, No Replies

Extracting all variables from a php script

using preg_match_all to extract all variables in a form into an array

         

WhosAWhata

6:57 pm on Jun 13, 2006 (gmt 0)

10+ Year Member



I'd really like to extract all variables from a script into an array. I think I would use preg_match_all, but i'm not sure and its a fairly complex match (at least for me).

exmple.php

<title><?=$title?></title>
<body>
<?
echo $body;
echo "copyright $c exapmle.com";
?>

extract.php

<?
$file = file_get_contents("example.php");
$pattern = "?"; //find everything starting with a $ until there is a break in the alphanumeric sequence
preg_match_all($pattern,$file,$out);

//$out would now be an array that contains "title", "body", and "c"

I would really appreciate help with the pattern

whoisgregg

8:54 pm on Jun 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe a different approach will also work? Take a look at get_defined_vars [php.net], it may be useful to you. :)