Reply
Show all variables that have been set on a page.
Old 05-21-2008, 04:37 PM Show all variables that have been set on a page.
Inet411's Avatar
Skilled Talker

Posts: 82
Name: programmer
Location: internet
Here's an odd question.
Is there any way (without knowing what variables have been set) to display the output of all the variable on your page.
ie.
$a=9;
$blah=10
$why_do_i_need_this_pointless_functions='yes';

ie. if there was a function like:
show_vars();
and it would output
9
10
yes

Remember 'without' knowing what variables are set, or even the variable names.

for example if it was all in a post I could easily:
foreach ($_POST as $key=>$value) {
echo $key." ".$value."<br />";
}

but if the variable have been set in the page and not in a post,get,session or cookie.

Strange request I know....
Inet411 is offline
Reply With Quote
View Public Profile Visit Inet411's homepage!
 
When You Register, These Ads Go Away!
Old 05-21-2008, 07:19 PM Re: Show all variables that have been set on a page.
Arenlor's Avatar
Ultra Talker

Posts: 463
Name: Jerod Lycett
Location: /home/arenlor
I did some research and found a few things, edited a few of them together to get this, which you should be able to edit as needed:
PHP Code:
<?php function vars($vars$exclude){
    
$temp1 array_values(array_diff(array_keys($vars), $exclude));
    
$temp2 = array();
    while (list(
$key$value) = each($temp1)) {
        global $
$value;
        
$temp2[$value] = $$value;
    }
    return 
$temp2;
}
$exclude = array('GLOBALS''_FILES''_COOKIE''_POST''_GET''_SERVER''_ENV''HTTP_ENV_VARS''HTTP_POST_VARS''HTTP_GET_VARS''HTTP_COOKIE_VARS''HTTP_SERVER_VARS''HTTP_POST_FILES''_REQUEST''exclude');
$vars get_defined_vars();
print 
"<pre>";
print_r(vars($vars$exclude));
print 
"</pre>";?>
__________________
PHP Code:
<?php echo "Hello World"?>
HTML Code:
<html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>
Arenlor is offline
Reply With Quote
View Public Profile Visit Arenlor's homepage!
 
Reply     « Reply to Show all variables that have been set on a page.
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12789 seconds with 12 queries