Welcome Guest, Not a member yet? Register   Sign In
Array to string for logging
#1

[eluser]RJ[/eluser]
Hello,

Is there a built in method that will take an array and convert to a string so i can log it? Presently I have to serialize the array to see anything in the log, but i dont like the output.

Thanks
#2

[eluser]jedd[/eluser]
[quote author="bullspit" date="1239221418"]
Is there a built in method that will take an array and convert to a string so i can log it? Presently I have to serialize the array to see anything in the log, but i dont like the output.
[/quote]

This is one of those problems that is defined by the solution you've come up with already, right?

What is the actual problem you have?

Lacking any context at all, I'll throw some random ideas at you. Lower your expections with serialize. Wrap a function around the serialize/deserialize functions so that your log better suits your taste. Use var_dump or print_r to dump the array into a preformatted string (ie. you'll need to wrap it in <pre> to make it readable) and store that. Again, not being sure how you are logging, or why, it's speculative whether any of these approaches might be suitable / adaptable.
#3

[eluser]RJ[/eluser]
Sorry your right, should have elaborated more.

I'm taking an SQL call array and trying to log the entire SELECT * etc string; i tried $
Code:
this->db->_compile_select();
which only returns the first part select *.

Serelizing allows the full string but in this format -
Code:
a:1:{i:0;a:14:{s:3:"num";s:3:"999";s:4:"name";s:15:

Using AR -
Code:
$this->db->select('*')->where('num', $dealer);.
$query = $this->db->get('fw_dealers');

I guess there is not simple solution, will stick with the serialize for now.

Thanks
#4

[eluser]jedd[/eluser]
Did $this->db->last_query(); not quite do what you want?
#5

[eluser]NogDog[/eluser]
You can set the optional 2nd parameter of print_r() to true to get its output as a string instead of printing it to the standard output.
Code:
error_log("This array sucks:\n" . print_r($array, true));
#6

[eluser]RJ[/eluser]
@jedd - exactly what i was looking for, thanks!

@noddog - thank you!




Theme © iAndrew 2016 - Forum software by © MyBB