PHP and js interactive sample code

怪我咯
Release: 2023-03-13 16:42:01
Original
1635 people have browsed it

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&#39;";  
$guest_name=addslashes($myrow[guest_name]);  
//$guest_name=str2js($myrow[guest_name],"&#39;");  
$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=&#39;return rec_delete(delete_mess)&#39;>删除</a>  
</body>  
</html>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template