How to prevent echo in PHP and get what it is inside?

时间:2016-08-31 12:22:55

标签: javascript php android html

Referring this post how-to-prevent-echo-in-php-and-catch-what-it-is-inside i am trying to get the output values from below mentioned php file but i can see still the values are getting printed in output of my php page.Any other suggestion are also welocme to get the output content from my php file to string without getting it echoed.Thanks!

<?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 code to get echo'ed values in HTML format

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);
            }
        }

2 个答案:

答案 0 :(得分: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
?>

如果这对您不起作用,请告诉我们正在回应的内容。

答案 1 :(得分:0)

检查运行代码内部情况的最佳方法是使用调试器,例如xdebug。了解如何安装它并与您选择的IDE一起使用,然后放置断点并使用监视来查看变量内部。 Here's how to do it with PhpStorm

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