11

I have some comments inside a drupal node, and tried

var_dump()

and

print_r()

to see the difference between them. I want to see what´s inside $content variable of $comment object.

I´ve tried both and what I get is the same output!

array(5) { ["#printed"]=> bool(true) ["comment_body"]=> array(18) { ["#theme"]=> string(5) "field" ["#weight"]=> int(0) ["#title"]=> string(10) "Comentario" ["#access"]=> bool(true) ["#label_display"]=> string(6) "hidden" ["#view_mode"]=> string(4) "full" ["#language"]=> string(3) "und" ["#field_name"]=> string(12) "comment_body" ["#field_type"]=> string(9) "text_long" ["#field_translatable"]=> string(1) "0" ["#entity_type"]=> string(7) "comment" ["#bundle"]=> string(21) "comment_node_noticias" ["#object"]=> object(stdClass)#105 (25) { ["cid"]=> string(5) "37616" ["pid"]=> string(1) "0" ["nid"]=> string(4) "4355" ["uid"]=> string(4) "1411" ["subject"]=> string(30) "Esperemos que así sea, ya que" ["hostname"]=> string(15) "190.246.225.229" ["created"]=> string(10) "1307259450" ["changed"]=> string(10) "1307259450" ["status"]=> string(1) "1" ["thread"]=> string(3) "01/" ["name"]=> string(11) "dominguezpm" ["mail"]=> string(0) "" ["homepage"]=> string(0) "" ["language"]=> string(0) "" ["node_type"]=> string(21) "comment_node_noticias" ["registered_name"]=> string(11) "dominguezpm" ["u_uid"]=> string(4) "1411" ["signature"]=> string(0) "" ["signature_format"]=> NULL ["picture"]=> string(1) "0" ["new"]=> int(0) ["comment_body"]=> array(1) { ["und"]=> array(1) { [0]=> array(3) { ["value"]=> string(235) 

[...]

What is the "readable" otion? I´ve read somewhere that print_r() is quite readable and ordered. But how can I understand what´s going on in there?

Any help will be very much appreciated! Thanks!

Rosamunda
  • 14,620
  • 10
  • 40
  • 70
  • 3
    var_dump is print_r but also includes type/size information. They're both very readable, if output properly. Given yours is all on a single line, you've probably copied this from some kind of an HTML view. View page source instead to see the raw output. – Marc B Aug 16 '12 at 21:49
  • You´re right, the page source showed it ok. – Rosamunda Aug 16 '12 at 22:02

3 Answers3

41

try to preformat it for better readability:

echo "<pre>";
print_r($some_var);
echo "</pre>";
raidenace
  • 12,789
  • 1
  • 32
  • 35
5

Try this code:

<pre>
<?php
   print_r($content);
   var_dump($content);
?>
</pre>

Using <pre> tells your browser what is inside the block is already preformatted.

Jocelyn
  • 11,209
  • 10
  • 43
  • 60
4

I recommend you to install Xdebug php extension - it customizes var_dump() to colored HTML output.

Example:

$pages = PageQuery::create()->find();
var_dump($pages);die;

Output:

enter image description here

Vitalii Zurian
  • 17,858
  • 4
  • 64
  • 81