How does alert display the results returned by the function method?

Source: Internet
Author: User
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 ......

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.