Javascript 如何在PHP中防止回声并获取其内部内容?
参考这篇文章,我试图从下面提到的php文件中获取输出值,但我仍然可以看到这些值被打印在我的php页面的输出中。任何其他建议也欢迎我将php文件中的输出内容转换为字符串,而不必回显。谢谢Javascript 如何在PHP中防止回声并获取其内部内容?,javascript,php,android,html,Javascript,Php,Android,Html,参考这篇文章,我试图从下面提到的php文件中获取输出值,但我仍然可以看到这些值被打印在我的php页面的输出中。任何其他建议也欢迎我将php文件中的输出内容转换为字符串,而不必回显。谢谢 <?php include('Crypto.php')?> <?php $workingKey='XXXX'; //Working Key should be provided here. $encResponse=$_POST["encResp"];
<?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);
?>
例如,检查正在运行的代码中发生的事情的最佳方法是使用调试器。了解如何安装它并与您选择的IDE一起使用,然后放置断点并使用手表查看内部变量
如果您无法安装调试器,或者您绝对需要保留这些值,请学习日志的概念。日志()有一个PHP-FIG标准,至少有一个工具可以实现它——例如,。检查运行代码内部的情况的最佳方法是使用调试器,例如。了解如何安装它并与您选择的IDE一起使用,然后放置断点并使用手表查看内部变量
如果您无法安装调试器,或者您绝对需要保留这些值,请学习日志的概念。有一个PHP-FIG日志记录标准()和至少一个实现它的工具-例如,.就像在问题的注释中一样,您可以将输入存储在变量中。不需要使用输出缓冲区,至少在您的示例中不需要
<?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
?>
如果这对您不起作用,请向我们展示正在回送的内容。与您问题的注释类似,您可以将输入存储在变量中。不需要使用输出缓冲区,至少在您的示例中不需要
<?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
?>
如果这不适用于您,请向我们展示正在回送的内容。您是指Javascript中的“console.log”之类的内容吗?存储数据,而不是回送数据。然后你可以将这些信息写入文件、数据库、错误日志、电子邮件等等。你为什么要这样做?无法将数据存储在变量中?我正在设计一个应用程序,来自服务器的响应在上面的php文件中。现在我希望此响应显示在我的应用程序页面中。你是说Javascript中的“console.log”之类的内容吗?存储数据,而不是回显数据。然后你可以将这些信息写入文件、数据库、错误日志、电子邮件等等。你为什么要这样做?无法将数据存储在变量中?我正在设计一个应用程序,服务器的响应在上面的php文件中。现在,我希望此响应在我的应用程序页面中显示。通过使用您的代码,没有任何内容将被回显,但我需要以字符串形式获取这些变量值(用于我的应用程序中的进一步处理),因此我使用Javascript类[问题代码编辑]要获取php页面的html内容,那么您使用的是Ajax,希望从服务器获取响应?是的,Philipp,没错,您收到了我的问题如果您使用的是JQuery,您可以定义响应的类型。在这种情况下,还必须将定义的类型发回。我记得一个简单的字符串或json是最常见的。应该传递响应的脚本必须回显它。我修改了我的答案。是的,通过使用您的代码,没有任何内容会被回显,但我需要以字符串形式获取这些变量值(以便在我的应用程序中进一步处理),因此我使用Javascript类[编辑问题代码]来获取php页面的html内容。所以您使用的是Ajax,希望从服务器获得响应?是的,Philipp,您收到了我的问题如果您使用JQuery,您可以定义响应的类型。在这种情况下,还必须将定义的类型发回。我记得一个简单的字符串或json是最常见的。应该传递响应的脚本必须回显它。我修改了我的答案。