当前位置: 编程技术>php
本页文章导读:
▪php 数组的创建、调用和更新实现代码
代码如下:<?php $array = array("key1" => "Simon", 2 => "Elaine"); //数组的创建 echo $array["key1"]; //输出Simon echo $array[2]; //输出Elaine ?> 代码如下:<?php $array = array("key1" => array(0 => 1, 1 => 10, 2 .........
▪在JavaScript中调用php程序
代码如下:<SCRIPT Language = "JavaScript"> function func() { if(confirm("Are you OK with this?")) { this.location = "ok.php?action=ok"; } else { this.location = "ok.php?action=cancel"; } } </SCRIPT> <html> <head> </head.........
▪隐性调用php程序的方法
调用方法:<script language = "javascript" src = "count.php"></script> count.php源码: 代码如下:<?php $file_name = "count.txt"; $fp = fopen($file_name,"r"); //打开文件读入当前计数 $count = fread($fp, filesize($fil.........
[1]php 数组的创建、调用和更新实现代码
来源: 互联网 发布时间: 2013-11-30
代码如下:
<?php
$array = array("key1" => "Simon", 2 => "Elaine"); //数组的创建
echo $array["key1"]; //输出Simon
echo $array[2]; //输出Elaine
?>
代码如下:
<?php
$array = array("key1" => array(0 => 1, 1 => 10, 2 => 100),
"key2" => array(0 => 5, 1 => 25, 2 => 125));
echo $array["key1"][0]; //输出1
echo $array["key1"][1]; //输出10
echo $array["key1"][2]; //输出100
echo $array["key2"][0]; //输出5
echo $array["key2"][1]; //输出25
echo $array["key2"][2]; //输出125
?>
代码如下:
<?php
$array = array("key1" => array(0 => 1, 1 => 10, 2 => 100), //定义数组
"key2" => array(0 => 5, 1 => 25, 2 => 125));
print_r($array); //输出数组
?>
代码如下:
<?php
$array = array("a", "b","c"); //定义数组
print_r($array); //输出数组
?>
代码如下:
<?php
$array = array("a", "b","c"); //定义数组
$array[0] = "Simon"; //修改数组元素
print_r($array); //输出数组
?>
[2]在JavaScript中调用php程序
来源: 互联网 发布时间: 2013-11-30
代码如下:
<SCRIPT Language = "JavaScript">
function func()
{
if(confirm("Are you OK with this?"))
{
this.location = "ok.php?action=ok";
}
else
{
this.location = "ok.php?action=cancel";
}
}
</SCRIPT>
<html>
<head>
</head>
<body>
<a href="#" href="#" onClick="javascript:func();">Please Click</a>
</body>
</html>
代码如下:
<?php
if($_GET["action"]=="ok")
{
echo "I'm OK!";
}
else
{
echo "I'm not OK!";
}
?>
[3]隐性调用php程序的方法
来源: 互联网 发布时间: 2013-11-30
调用方法:
<script language = "javascript" src = "count.php"></script>
count.php源码:
<?php
$file_name = "count.txt";
$fp = fopen($file_name,"r"); //打开文件读入当前计数
$count = fread($fp, filesize($file_name));
fclose($fp);
$count++; //计数加1
$fp = fopen($file_name, "w"); //再次打开文件写入更新后的计数
fwrite($fp, $count);
fclose($fp);
echo "document.write('".$count."')"; //输出JavaScript代码,返回计数
?>
<script language = "javascript" src = "count.php"></script>
count.php源码:
代码如下:
<?php
$file_name = "count.txt";
$fp = fopen($file_name,"r"); //打开文件读入当前计数
$count = fread($fp, filesize($file_name));
fclose($fp);
$count++; //计数加1
$fp = fopen($file_name, "w"); //再次打开文件写入更新后的计数
fwrite($fp, $count);
fclose($fp);
echo "document.write('".$count."')"; //输出JavaScript代码,返回计数
?>
最新技术文章: