Loading...

How to learn the variables

April 25th, 2011

There are situations, when it is necessary to learn the variables’ value on the defined step of script performing. Certainly, there is a built-in function fn_print_r() in CS-Cart, which resolves this task, but not completely. What should we do, if it is necessary to catch the variables’ value in the Ajax query process executing? I offer to use the function, which will write the variable value into the file.

<?php
function fn_write_r()
{
	static $count = 0;
	$args = func_get_args();

	$fp = fopen('ajax_result.html', 'w+');

	if (!empty($args)) {
		fwrite($fp, '<ol style="font-family: Courier; font-size: 12px; border: 1px solid #dedede; background-color: #efefef; float: left; padding-right: 20px;">');

		foreach ($args as $k => $v) {
			$v = htmlspecialchars(print_r($v, true));
			if ($v == '') {
				$v = '    ';
		}

			fwrite($fp, '<li><pre>' . $v . "\n" . '</pre></li>');
		}
		fwrite($fp, '</ol><div style="clear:left;"></div>');
	}

	
	$count++;
}
?>

As far as you can see, this function creates the 'ajax_result.html' file, which includes all values of received arguments. If you run the file in the browser, you will see that the displayed result has the same view as result of the fn_print_r() executing.

 

Comments

*****

"Woot, I will ceartinly put this to good use!"

New post

Type the characters you see in the picture below.

Up