如何防止PHP中的echo,并得到它是什么

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

本文关键字:它是什么 echo 何防止 PHP 中的      更新时间:2023-09-26

参考这篇文章如何防止echo-in-php和catch- it-is-inside我试图从下面提到的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);
?>

获取HTML格式回显值的JAVASCRIPT代码

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

就像在你的问题的注释中一样,你可以将输入存储在一个变量中。输出缓冲区的使用是不必要的,至少在您的示例中不是这样。

<?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
?>

如果您不这样做,请告诉我们回显的内容。

检查正在运行的代码内部发生了什么,最好的方法是使用调试器,例如xdebug。了解如何安装它并与您选择的IDE一起使用,然后放置断点并使用监视来窥视变量内部。下面是如何在PhpStorm中做到这一点。

如果您不能安装调试器,或者您绝对需要持久化这些值,请学习日志的概念。有一个PHP-FIG日志记录标准(PSR-3)和至少一个实现它的工具-例如,独白。