2016-08-31 26 views
0

引用这个帖子how-to-prevent-echo-in-php-and-catch-what-it-is-inside我想从下面提到的php文件中获取输出值,但是我仍然可以看到这些值在我的php页面的输出中得到了打印。任何其他建议也欢迎从我的php中获取输出内容文件字符串没有得到它回声。谢谢!如何防止在PHP中的回声,并得到它在里面?

<?php include('Crypto.php')?> 
<?php  
    $workingKey='XXXX';  //Working Key should be provided here. 
    $encResponse=$_POST["encResp"];   //This is the response sent by the Server 
    $rcvdString=decrypt($encResponse,$workingKey);  //Crypto Decryption used as per the specified working key.  
    $order_status=""; 
    $order_id=0;   
    $decryptValues=explode('&', $rcvdString); 
    $dataSize=sizeof($decryptValues); 
    echo "<center>";  
    for($i = 0; $i < $dataSize; $i++) 
    { 
     $information=explode('=',$decryptValues[$i]); 
     if($i==0) $order_id = $information[1]; 
     if($i==1) $tracking_id = $information[1]; 
     if($i==3) $order_status = $information[1]; 
    } 
     ob_start(); 
     echo $order_id."_"; 
     $out1 = ob_get_contents(); 
     echo $tracking_id."_"; 
     $out2 = ob_get_contents(); 
     echo $order_status; 
     $out3 = ob_get_contents(); 
     ob_end_clean(); 
     var_dump($out3); 
?> 

JavaScript代码的HTML格式

class MyJavaScriptInterface 
     { 
      @JavascriptInterface 
      @SuppressWarnings("unused") 
      public void processHTML(final String html) 
      { 


       String order_page = ""+Html.fromHtml(html);//process php output to html 

       String CCAvenueOrder_id = order_page.split("\\_")[0]; 
       String CCAvenueTacking_id=order_page.split("\\_")[1]; 
       String CCAvenueOrderStatus=order_page.split("\\_")[2]; 


       // process the html as needed by the app 
       String status = null; 

       if(html.indexOf("Failure")!=-1){ 
        status = "Transaction Declined!"; 
       }else if(html.indexOf("Success")!=-1){ 
        status = "Transaction Successful!"; 
       }else if(html.indexOf("Aborted")!=-1){ 
        status = " Transaction Cancelled!"; 
       }else{ 
        status = "Status Not Known!"; 
       } 
       //Toast.makeText(getApplicationContext(), status,  Toast.LENGTH_SHORT).show(); 
       Intent intent = new  Intent(getApplicationContext(),StatusActivity.class); 

       startActivity(intent); 
      } 
     } 
+0

你的意思是像JavaScript的“console.log”? –

+0

存储数据而不是回显它。然后你可以将这些信息写入文件,db,error_log,给它发邮件等。 – chris85

+0

你为什么要这样做?不能将数据存储在变量中? –

回答

0

最好的办法得到echo'ed值检查是怎么回事内运行的代码是使用调试器,例如xdebug。了解如何安装并使用您选择的IDE,然后放置断点并使用手表来查看变量内部。 Here's how to do it with PhpStorm

如果您无法安装调试器,或者您绝对需要保留这些值,请了解日志的概念。有一个PHP-FIG日志记录标准(PSR-3)和至少一个实现它的工具 - 例如,Monolog

2

和你的问题的评论一样,你可以将输入存储在一个变量中。输出缓冲区的使用是没有必要的,至少在你的例子中没有。

<?php  
    $workingKey='XXXX';  //Working Key should be provided here. 
    $encResponse=$_POST["encResp"];   //This is the response sent by the Server 
    $rcvdString=decrypt($encResponse,$workingKey);  //Crypto Decryption used as per the specified working key.  
    $order_status=""; 
    $order_id=0;   
    $decryptValues=explode('&', $rcvdString); 
    $dataSize=sizeof($decryptValues); 
    $output = "<center>";  
    for ($i = 0; $i < $dataSize; $i++) { 
     $information=explode('=',$decryptValues[$i]); 
     if($i==0) $order_id = $information[1]; 
     if($i==1) $tracking_id = $information[1]; 
     if($i==3) $order_status = $information[1]; 
    } 
    $output .= $order_id."_"; 
    $output .= $tracking_id."_"; 
    $output .= $order_status; 
    echo $output; // response for ajax request as simple string 
?> 

如果这不适合你,请告诉我们什么是回声。

+0

是的通过使用你的代码什么都不会echo'ed,但我需要在字符串中获得这些变量值(在我的应用程序进一步处理),所以我使用Javascript类[编辑问题代码]获取PHP页面的HTML内容 –

+0

所以你使用Ajax,并希望从服务器获得响应? –

+0

是的Philipp正好,你有我的问题 –