Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: Variable names


Message #1 by Richard Price <richard.price@f...> on Thu, 23 Aug 2001 10:11:31 +0100
> Is there a way to get at variable names in php so i can output the variable
> names onto a page instead of what they contain? ie if:
> $var1 = "this is the content";
> then i want to output var1 onto my page instead of the "this is the content"

When working with forms, I use this code to display all of the variable names
and their values:


DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>Show Vars</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</HEAD>
<BODY>

<?php

$Vars = "HTTP_${REQUEST_METHOD}_VARS";

echo "<br>
<b>$HTTP_REFERER</b>
<br><br>
<b>$Vars</b>
<br><br>
<table border>
<tr>
<th>Index</th<th>Element</th>
</tr>";

while (list($IndexValue, $ElementContents) = each(${${Vars}}))
{
        echo "<tr>
        <td>$IndexValue</td><td align=right>$ElementContents</td>
        </tr>";
}

echo "</table>";

?>

</BODY>
</HTML>


--
   ~
  . .
  /V\
 // \\
/(   )\
 ^`~'^




  Return to Index