You are here: Re: [PHP] How to print variable name and contents « PHP « IT news, forums, messages
Re: [PHP] How to print variable name and contents

Posted by Richard Davey on 06/16/05 04:42

Hello,

Wednesday, June 15, 2005, 2:33:48 PM, you wrote:

ncn> I want to write a trace procedure and call it with variable
ncn> names, and I am having trouble with the syntax. My goal is to
ncn> have a procedure that will echo lines such as:

ncn> Trace: $myvar="the contents of $myvar

ncn> My attempt that didn't work is to write a function:

ncn> function my_trace($m){
ncn> echo ("\n<br>TRACE: $m = ");
ncn> eval("\$t=\"$m\";");
ncn> echo($t."<br>\n");
ncn> }

Here's one way:

function my_trace ($varname, $varvalue)
{
$varvalue = print_r($varvalue, true);
echo "TRACE: $varname = \"$varvalue\"<br />";
}

my_trace("\$my_var", $my_var);

Another might be to look at the var_dump and var_export functions.

Best regards,

Richard Davey
--
http://www.launchcode.co.uk - PHP Development Services
"I do not fear computers. I fear the lack of them." - Isaac Asimov

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация