How does alert display the results returned by the function method php; alert; function
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?
Reply to discussion (solution)
$ Error: I don't know what it is to print in php.
$ Error: capture error information from the output file and display it to the user in a dialog box.
The value of $ error can be correctly obtained in this program, but alert cannot pop up a dialog box.
It's okay if I debug it for you. a prompt is displayed.
Here I am, I just want ......
Is the return value in function similar to substr? If a string is directly returned, it can be popped up.
$ Error = check ($ out );
Echo $ error; what is the result?
Send your out.txt.
My out.txt is like this.
Send your out.txt.
My out.txt is like this.
I seem to have found some reasons.
If there is only one or the last row of the file is "# ERROR abc", it will pop up normally, but if there is other information behind it, my program will not work...
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 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.
I know how to change it, but I don't know why ......
Just extract all the required strings. for example, "return substr ($ line, 8, 5)" will pop up normally. Is it true if it is not the last line, substr will get the line break at the end of a row, but alert cannot process it ......