![]() |
Array to string for logging - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Array to string for logging (/showthread.php?tid=17563) |
Array to string for logging - El Forum - 04-08-2009 [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 Array to string for logging - El Forum - 04-08-2009 [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. Array to string for logging - El Forum - 04-08-2009 [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(); 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);. I guess there is not simple solution, will stick with the serialize for now. Thanks Array to string for logging - El Forum - 04-08-2009 [eluser]jedd[/eluser] Did $this->db->last_query(); not quite do what you want? Array to string for logging - El Forum - 04-08-2009 [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)); Array to string for logging - El Forum - 04-08-2009 [eluser]RJ[/eluser] @jedd - exactly what i was looking for, thanks! @noddog - thank you! |