Jump to content

Need help formatting backtrace


eldan88
Go to solution Solved by Psycho,

Recommended Posts

Hey,

 

 I am trying to format back trace in a nice readable format, but I having troubles doing so. I  tried using print_r function but it is not working. Any suggestion on how to format backtrace?

 

Below is my code

   function a($arg) {
       b("Bob");   
      }
      
          function b($arg) {
          d('delta');
      }
      
      
      function d ($arg) {
          var_dump(debug_backtrace());
      }
      
      
  
     
      
      a('alpha')
      
Link to comment
Share on other sites

  • Solution

What do you mean "it is not working"? Exactly what are you getting? The code you have above does exactly what I expect - it outputs the array returned from the debug_backtrace() function.

 

EDIT: If your issue is that the array output is not "pretty" then the issue is an HTML problem and not a PHP problem (and this is in the wrong forum). There are many options to make the output pretty. The most straightforward is putting it within PRE tags so white-space and line-breaks are rendered in the HTML display.

 

function d ($arg)
{
    echo "<pre>";
    var_dump(debug_backtrace());
    echo "</pre>";
}

 

Otherwise you can create your own code to loop through the array and format the output any way you want.

Edited by Psycho
Link to comment
Share on other sites

What do you mean "it is not working"? Exactly what are you getting? The code you have above does exactly what I expect - it outputs the array returned from the debug_backtrace() function.

 

EDIT: If your issue is that the array output is not "pretty" then the issue is an HTML problem and not a PHP problem (and this is in the wrong forum). There are many options to make the output pretty. The most straightforward is putting it within PRE tags so white-space and line-breaks are rendered in the HTML display.

function d ($arg)
{
    echo "<pre>";
    var_dump(debug_backtrace());
    echo "</pre>";
}

Otherwise you can create your own code to loop through the array and format the output any way you want.

I was trying to out put in pretty HTML but the pre tags did the job! Thanks!!

Edited by eldan88
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.