Home >Backend Development >PHP Tutorial >alert怎么显示function方法返回的结果

alert怎么显示function方法返回的结果

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 11:47:191786browse

alert如何显示function方法返回的结果
如下代码:
function check($out) {
  $file_handle = fopen($out, 'r');
  while (!feof($file_handle)) {
    $line = fgets($file_handle);
    if (substr($line, 0, 6) == "#ERROR") {
      return substr($line, 8);
    }
  }
  fclose($file_handle);
  return "";
}

$out = "output/out.txt";
$error = check($out);
if ($error != "") {
  echo "<script>alert('$error');</script>";
  exit;
}
?>

此时无法弹出alert对话框。。。
但如果把check方法的return改为 return "abc",就能够弹出alert对话框了

我需要alert弹出的内容是从文件中获得的,请问如何修改?
------解决方案--------------------

function check($out) {<br />  $file_handle = fopen($out, 'r');<br />  while (!feof($file_handle)) {<br />    $line = fgets($file_handle);<br />    if (substr($line, 0, 6) == "#ERROR") {<br />      return preg_replace("/\s/","",substr($line, 8));//去掉换行<br />    }<br />  }<br />  fclose($file_handle);<br />}<br /><br />$out = "out.txt";<br />$error = check($out);<br />if ($error != "") {<br />  echo "<script>alert(\"$error\");</script>";<br />  exit;<br />}

取出一行存在换行问题 把换行去掉就行了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn