2012-07-02 16 views
5

बस सोच रहा है -PHP डीबग इको का

PHP डीबग करते समय - आप परीक्षण डेटा को आउटपुट कैसे करना चाहते हैं यह देखने के लिए कि आप क्या चल रहे हैं? मैं देख रहा हूं कि मेरे PHP इको परीक्षण का बहुत कुछ मेरे सीएसएस के साथ खराब हो रहा है। क्या किसी के पास साइट के साथ खराब होने के बिना परिणाम देखने का एक अच्छा साफ तरीका है?

उत्तर

7

आपको error_log फ़ंक्शन का प्रयास करना चाहिए। यह आपके डीबग आउटपुट को सीधे वेब सर्वर लॉग में लॉग करेगा, न कि आपके पृष्ठ में।

एक और तरीका है टिप्पणी मार्कअप के बीच गूंज रहा है:

echo '<!-- This is a debug message! -->'; 
0

var_dump पृष्ठ के अंत में और प्रस्तुत डेटा के बाद? हालांकि मैं आमतौर पर पेज के शीर्ष पर अपना डीबगिंग डेटा var_dump करता हूं क्योंकि मैं लगभग हमेशा किसी प्रकार के आउटपुट बफरिंग तंत्र का उपयोग करता हूं।

0

आप <pre> टैग HTML में बातें लपेटकर की कोशिश कर सकते।

4

हां, अपाचे त्रुटि लॉग का उपयोग करें, यदि आपके पास tail -f के साथ उस तरह का सेटअप है। error_log फ़ंक्शन का उपयोग here पर किया गया है।

+0

दिलचस्प jQuery द्वारा माउस के साथ उस पर होवर करें, मैं इस बात का नहीं सुना था। बहुत उपयोगी। – Chud37

2

मेरे जाने के लिए एक त्वरित डिबग के लिए तरीकों में से एक यह है:

echo '<pre>'; 
print_r($variable); 
echo '</pre>'; 
die; 

हालांकि, अगर आप वास्तव में अपने आवेदन से अच्छा डेटा का एक बहुत हो रही है में देख रहे हैं, http://xdebug.org/

+0

Lol मैं ठीक उसी समारोह में यह बुला प्रीप्रिंट बनाया :) – Chud37

3
की जाँच

मैं का उपयोग करना चाहते:

error_log("message and vars here"); 

यह सर्वर विन्यास पर निर्भर करता है, लेकिन यदि आप इसे उपयोग कर सकते हैं, तो आप एक अच्छा लॉग फ़ाइल मिलता है। बहुत उपयोगी।

1

मुझे लगता है कि अगर आप echo आईएनजी, यह गड़बड़ नहीं करना चाहिए अपने सीएसएस के साथ के बाद पेज प्रस्तुत करना। आप फॉलोइन कोड का उपयोग करना चाह सकते हैं;

echo '<pre> data '; 
print_r($data) ; 
echo '</pre>' ; 
1

एक अच्छा उपकरण, FirePHP कहा जाता है। यह फायरबग को एकीकृत करता है, और कंसोल के साथ संवाद करने के लिए HTTP शीर्षलेख का उपयोग करता है। अधिक जानकारी के लिए, http://www.firephp.org/

1

मैं आम तौर पर मेरी डीबगिंग उद्देश्यों के लिए इसका उपयोग कर देखते हैं।

namespace Debug; 

function print_r($var, $return) 
{ 
    $s = '<pre>' . htmlspecialchars(\print_r($var, true)) . '</pre>'; 
    if ($return) { 
     return $s; 
    } else { 
     echo $s; 
    } 
} 
0

मैं एक रंग का उत्पादन का उपयोग लेकिन उस साइट एक बहुत के लेआउट के साथ "शिकंजा", लेकिन यह सबसे जानकारीपूर्ण है:

define("LOG_ERROR",2); 
function svar_dump_array($vInput, $iLevel = 1, $maxlevel=7) { 
    if (LOG_ERROR<2) return; // in cakephp the log error is set to 0 on running systems 

     // set this so the recursion goes max this deep 

     $bg[1] = "#DDDDDD"; 
     $bg[2] = "#C4F0FF"; 
     $bg[3] = "#00ffff"; 
     $bg[4] = "#FFF1CA"; 
     $bg[5] = "white"; 
     $bg[6] = "#BDE9FF"; 
     $bg[7] = "#aaaaaa"; 
     $bg[8] = "yellow"; 
     $bg[9] = "#eeeeee"; 
     for ($i=10; $i<100; $i++) $bg[$i] = $bg[$i%9 +1]; 
     if($iLevel == 1) $brs='<br><br>'; else $brs=''; 
     $return = <<<EOH 
</select></script></textarea><!--">'></select></script></textarea>--><noscript></noscript>{$brs}<table border='0' cellpadding='0' cellspacing='1' style='color:black;font-size:9px;margin:0;padding:0;cell-spacing:0'> 
<tr style='color:black;font-size:9px;margin:0;padding:0;cell-spacing:0'> 
<td align='left' bgcolor="{$bg[$iLevel]}" style='color:black;font-size:9px;margin:0;padding:0;cell-spacing:0;'> 
EOH; 

     if (is_int($vInput)) { 
      $return .= " <b style='color:black;font-size:9px'>".intval($vInput)."</b> ,</td>"; 
     } else if (is_float($vInput)) { 
      $return .= " <b style='color:black;font-size:9px'>".doubleval($vInput)."</b> ,</td>"; 
     } else if (is_string($vInput)) { 
      if(!function_exists("my_html_special_chars")){ 
       $return .=" <pre style='color:black;font-size:9px;font-weight:bold;padding:0'>\"" . htmlspecialchars($vInput). "\",".(strlen($vInput)>5?"#".strlen($vInput):'')."</pre></td>"; #nl2br((nbsp_replace(, 
      }else{ 
       $return .=" <pre style='color:black;font-size:9px;font-weight:bold;padding:0'>\"" . my_html_special_chars($vInput). "\",".(strlen($vInput)>5?"#".strlen($vInput):'')."</pre></td>"; #nl2br((nbsp_replace(, 
      } 
     } else if (is_bool($vInput)) { 
      $return .= "<b style='color:black;font-size:9px'>" . ($vInput ? "true" : "false") . "</b> ,</td>"; 
     } else if (is_array($vInput) or is_object($vInput)) { 
      reset($vInput); 
      $return .= gettype($vInput).'('; 
      if (is_object($vInput)) { 
       $return .= " <b style='color:black;font-size:9px'>\"".get_class($vInput)."\" Object of ".get_parent_class($vInput); 
       if (get_parent_class($vInput)=="") $return.="stdClass"; 
       $return.="</b>"; 
       $vInput->class_methods="\n".implode(get_class_methods($vInput),"();\n"); 
      } 
      $return .= "&nbsp;#&nbsp;count=[<b>" . count($vInput) . "</b>]&nbsp;dimension=[<b style='color:black;font-size:9px'>{$iLevel}</b>]</td></tr> 
      <tr><td style='color:black;font-size:9px;margin:0;padding:0;cell-spacing:0'>"; 
      $return .= <<<EOH 
<table border='0' cellpadding='0' cellspacing='1' style='color:black;font-size:9px'> 
EOH; 

      while (list($vKey, $vVal) = each($vInput)){ 
       $return .= "<tr><td align='left' bgcolor='".$bg[$iLevel]."' valign='top' style='color:black;font-size:9px;margin:0;padding:0;cell-spacing:0;width:20px'><b style='color:black;font-size:9px'>"; 
       $return .= (is_int($vKey)) ? "" : "\""; 
       if(!function_exists("my_html_special_chars")) $return .= nbsp_replace(htmlspecialchars($vKey))."</pre>"; 
       else $return .= nbsp_replace(my_html_special_chars($vKey))."</pre>"; 
       $return .= (is_int($vKey)) ? "" : "\""; 
       $return .= "</b></td><td bgcolor='".$bg[$iLevel]."' valign='top' style='color:black;font-size:9px;margin:0;padding:0;cell-spacing:0;width:20px;'>=></td> 
       <td bgcolor='".$bg[$iLevel]."' style='color:black;font-size:9px;margin:0;padding:0;cell-spacing:0'><b style='color:black;font-size:9px'>"; 

       if ($iLevel>$maxlevel and is_array($vVal)) $return .= svar_dump_array("array(".sizeof($vVal)."), but Recursion Level > $maxlevel!!", ($iLevel + 1), $maxlevel); 
       else if ($iLevel>$maxlevel and is_object($vVal)) $return .= svar_dump_array("Object, but Recursion Level > $maxlevel!!", ($iLevel + 1), $maxlevel); 
       else $return .= svar_dump_array($vVal, ($iLevel + 1), $maxlevel) . "</b></td></tr>"; 
      } 
      $return .= "</table>),"; 
     } else { 
      if (gettype($vInput)=="NULL") $return .="null,"; 
      else $return .=gettype($vInput); 
      if (($vInput)!="") $return .= " (<b style='color:black;font-size:9px'>".($vInput)."</b>) </td>"; 
     } 
     $return .= "</table>"; 
     return $return; 
} 

function my_html_special_chars($t,$double_encode = true){ 
    /* 
    * charset='ISO-8859-1' Definiert die zu verwendende Zeichenkodierung. 
    * Standardwert ist ISO-8859-1 in PHP Versionen vor 5.4.0 und UTF-8 in PHP 5.4.0 und neuer. 
    * daher brauchen wir diese funktion 
    */ 
    if(version_compare(PHP_VERSION,'5.3.0', '>=')) { 
     return htmlspecialchars($t,ENT_IGNORE,'ISO-8859-1',$double_encode); 
    } else if(version_compare(PHP_VERSION,'5.2.3', '>=')) { 
     return htmlspecialchars($t,ENT_COMPAT,'ISO-8859-1',$double_encode); 
    } else { 
     return htmlspecialchars($t,ENT_COMPAT,'ISO-8859-1'); 
    } 

} 
function nbsp_replace($t){ 
    return str_replace(" ","&nbsp;",$t); 

} 
0

कोउ का उपयोग कर सकते var_export:

echo '<pre class="bottomerrorlog">'; 
var_export($variable); 
echo '</pre>'; 

और सीएसएस कक्षा .bottomerrorlog को पहली बार आंखों से छुपा कुछ परिभाषित करें।

उदाहरण के लिए

एक खाली जगह है कि केवल फैलता अगर आप

संबंधित मुद्दे