How does alert display the following code returned by the function method: & lt ;? Phpfunction & nbsp; check ($ out) & nbsp ;{& nbsp; & nbsp; $ file_handle & nbsp ;=& nbsp; fopen ($ out, & nbsp; how does 'R' alert display the results returned by the function method?
The following code:
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;
}
?>
The alert dialog box cannot be displayed...
However, if you change the return of the check method to return "abc", the alert dialog box will pop up.
I need the content popped up by alert to be obtained from the file. how can I modify it?
------ Solution --------------------
Function check ($ out ){
$ File_handle = fopen ($ out, 'r ');
While (! Feof ($ file_handle )){
$ Line = fgets ($ file_handle );
If (substr ($ line, 0, 6) = "# ERROR "){
Return preg_replace ("/\ s/", "", substr ($ line, 8); // remove the line feed.
}
}
Fclose ($ file_handle );
}
$ Out = "out.txt ";
$ Error = check ($ out );
If ($ error! = ""){
Echo "script" alert (\ "$ error \"); script ";
Exit;
}
There is a line break problem in removing the line break.