Home > Article > Backend Development > PHP and js interactive sample code
All PHP applications are completed through WEB server (such as IIS or Apache) and PHP engine program interpretation and execution. The working process:
(1) When the user is browsing Enter the file name of the PHP page to be accessed in the server address, and then press Enter to trigger the PHP request and transmit the request to a WEB server that supports PHP.
(2) The WEB server accepts this request and determines it based on its suffix. If it is a PHP request, the WEB server takes out the PHP application the user wants to access from the hard disk or memory and sends it to the PHP engine. program.
(3) The PHP engine program (usually PHP.exe) will scan the file sent from the WEB server from beginning to end, read it from the background according to the command, process the data, and dynamically generate the corresponding HTML page.
(4) The PHP engine will generate an HTML page and return it to the WEB server. The WEB server then returns the HTML page to the client browser.
So if PHP wants to pass a value to an HTML JS script, how to do it? You can first define it before the variable you need to use, as in the following example:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>Untitled</title> <script language="javascript"> <!-- function rec_delete(message){ return confirm(message); } //--> </script> </head> <body> <?php $myrow[guest_name]="asdf\""; $myrow[guest_name]="asdf'"; $guest_name=addslashes($myrow[guest_name]); //$guest_name=str2js($myrow[guest_name],"'"); $dele_mess="真的要删除这个留言吗?\n留言姓名:$guest_name($myrow[guest_ip])"."\n留言时间:$myrow[guest_time]"; echo "<script>"; echo "delete_mess=\"$dele_mess\""; echo "<\/script>"; ?> <a href="<?php echo "$PHP_SELF?opt=delete"; ?>" onClick='return rec_delete(delete_mess)'>删除</a> </body> </html>
The above is the detailed content of PHP and js interactive sample code. For more information, please follow other related articles on the PHP Chinese website!