php教程 soap 调用获取返回信息
trace soap message
获取 soap返回信息
<?php
$ws = "http://www.111cn.net/sd/2001/temperatureservice.wsdl";
$zipcode = "23590";
$client = new soapclient($ws,array('trace' => 1));
$temperature = $client->gettemp($zipcode);
echo htmlspecialchars($client->__getlastrequest());
?>
得到函数原型从wsdl
<?php
$ws = "http://www.www.111cn.net/sd/2001/temperatureservice.wsdl";
$client = new soapclient($ws);
var_dump($client->__getfunctions());
?>
<?php
$ws = "http://www.xmethods.net/sd/2001/temperatureservice.wsdl";
$zipcode = "12312";
$client = new soapclient($ws,array('trace' => 1));
$temperature = $client->gettemp($zipcode);
echo htmlspecialchars($client->__getlastresponse());
?>
他们利用了递归的方法来实例目录遍历,可以查找出无限级目录的文件与文件夹中的文件并显示,下面是实例代码
<?php教程
$dir = 'f:game';
function read_dir_all($dir) {
$ret = array('dirs'=>array(), 'files'=>array());
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if($file != '.' && $file !== '..') {
$cur_path = $dir . directory_separator . $file;
if(is_dir($cur_path)) {
$ret['dirs'][$cur_path] = read_dir_all($cur_path);
} else {
$ret['files'][] = $cur_path;
}
}
}
closedir($handle);
}
return $ret;
}
$p = read_dir_all($dir);
echo '<pre>';
var_dump($p);
echo '</pre>';
?>
由于checkbox特殊性所以我们要获取它的值,在很我语言中都不一样的,在php教程 以我们是以数组形式来处理,并且利用遍历他的值,下面有大量实例。
<html>
<head>
<title>checkbox demo</title>
</head>
<body>
<h1>checkbox demo</h1><h3>demonstrates checkboxes</h3>
<form action ="handleformcheckbox.php"><ul>
<li><input type ="checkbox" name ="chkfries" value ="11.00">fries</li>
<li><input type ="checkbox" name ="chksoda" value ="12.85">soda</li>
<li><input type ="checkbox" name ="chkshake" value ="1.30">shake</li>
<li><input type ="checkbox" name ="chkketchup" value =".05">ketchup</li>
</ul>
<input type ="submit">
</form></body>
</html>
<!-- handleformcheckbox.php
<html>
<head>
<title>checkbox demo</title>
</head>
<body>
<h3>demonstrates reading checkboxes</h3>
<?
print <<<here
chkfries: $chkfries <br>
chksoda: $chksoda <br>
chkshake: $chkshake <br>
chkketchup: $chkketchup <br>
<hr>here;
$total = 0;
if (!empty($chkfries)){
print ("you chose fries <br>");
$total = $total + $chkfries;
}if (!empty($chksoda)){
print ("you chose soda <br>");
$total = $total + $chksoda;
}if (!empty($chkshake)){
print ("you chose shake <br>");
$total = $total + $chkshake;
}if (!empty($chkketchup)){
print ("you chose ketchup <br>");
$total = $total + $chkketchup;
}print "the total cost is $$total";
?>
</body>
</html>
-->
实例
<html>
<head>
<title>using default checkbox values</title>
</head>
<body>
<?php
$food = $_get[food];
$self = htmlentities($_server['php_self']);
if (!empty($food)) {
echo "the foods selected are:<br />";
foreach($food as $foodstuf)
{
echo "<strong>".htmlentities($foodstuf)."</strong><br />";
}
}
else
{
echo ("<form action="$self" ");
echo ('method="get">
<fieldset>
<label>italian <input type="checkbox" name="food[]" value="italian" />
</label>
<label>mexican <input type="checkbox" name="food[]" value="mexican" />
</label>
<label>chinese <input type="checkbox" name="food[]" value="chinese"
checked="checked" /></label>
</fieldset>
<input type="submit" value="go!" >');
}
?>
</body>
</html>
多选checkbox
<?php
$options = array('option 1', 'option 2', 'option 3');$valid = true;
if (is_array($_get['input'])) {
$valid = true;
foreach($_get['input'] as $input) {
if (!in_array($input, $options)) {
$valid = false;
}
}
if ($valid) {
//process input
}
}
?>
实例checkbox多值获取
<html>
<head>
<title>using default checkbox values</title>
</head>
<body>
<?php
$food = $_get["food"];//www.3ppt.com
if (!empty($food)){
echo "the foods selected are: <strong>";
foreach($food as $foodstuff){
echo '<br />'.htmlentities($foodstuff);
}
echo "</strong>.";
}
else {
echo ('
<form action="'. htmlentities($_server["php_self"]).'" method="get">
<fieldset>
<label>
italian
<input type="checkbox" name="food[]" value="italian" />
</label>
<label>
mexican
<input type="checkbox" name="food[]" value="mexican" />
</label>
<label>
chinese
<input type="checkbox" name="food[]" value="chinese" checked="checked" />
</label>
</fieldset>
<input type="submit" value="go!" />
</form> ');
}
?>
</body>
</html>
file_get_contents() 函数把整个文件读入一个字符串中。
和 file() 一样,不同的是 file_get_contents() 把文件读入一个字符串。
file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法。如果操作系统支持,还会使用内存映射技术来增强性能。
语法
file_get_contents(path,include_path,context,start,max_length)参数 描述
path 必需。规定要读取的文件。
include_path 可选。如果也想在 include_path 中搜寻文件的话,可以将该参数设为 "1"。
context 可选。规定文件句柄的环境。
context 是一套可以修改流的行为的选项。若使用 null,则忽略。
start 可选。规定在文件中开始读取的位置。该参数是 php教程 5.1 新加的。
max_length 可选。规定读取的字节数。该参数是 php 5.1 新加的。
php代码
<?php
function post($url, $post = null)
{
$context = array();
if (is_array($post))
{
ksort($post);
$context['http'] = array
(
'method' => 'post',
'content' => http_build_query($post, '', '&'),
);
}
return file_get_contents($url, false, stream_context_create($context));
}
$data = array
(
'name' => 'test',
'email' => 'test@gmail.com',
'submit' => 'submit',
);
echo post('http://localhost/5-5/request_post_result.php', $data);
?>
接收数据:request_post_result.php 接收经过post的数据:
php代码
<?php
echo $_post['name'];
echo $_post['email'];
echo $_post['submit'];
echo "fdfd";
?>
实例二
/**
* 其它版本
* 使用方法:
* $post_string = "app=request&version=beta";
* request_by_other('http://facebook.cn/restserver.php',$post_string);
*/
function request_by_other($remote_server,$post_string){
$context = array(
'http'=>array(
'method'=>'post',
'header'=>'content-type: application/x-www-form-urlencoded'."rn".
'user-agent : jimmy's post example beta'."rn".
'content-length: '.strlen($post_string)+8,
'content'=>'mypost='.$post_string)
);
$stream_context = stream_context_create($context);
$data = file_get_contents($remote_server,false,$stream_context);
return $data;
}
数组的排序
在php教程中,排序方式有三种,通过索引排序、通过值排序(不保留原索引)、通过值排序(保留原索引)。每种又分为升序、降序以及用户定义顺序三个函数。它们分别如下:
通过索引排序:①升序 ksort() ②降序 krsort() ③用户定义顺序 uksort()
不保留原索引值排序:①升序 sort() ②降序 rsort() ③用户定义顺序 usort()
保留原索引值排序:①升序 asort() ②降序 arsort() ③用户定义顺序 uasort()
在php中,也可以用array_multisort来一次排序多个数组,不过项目中可能用得比较少。
翻转数组,把数字索引翻转,索引重新从0开始:array_reverse()
把索引和值调换:array_flip()
随机顺序:shuffle()
迭代器遍历
$test01 = array('a', 'b', 'c');
// for
for ($i = 0; $i < count($test01); $i++) {
echo $test01[$i];
}
// foreach value only
foreach ($test01 as $value) {
echo $value;
}
// foreach key and value
$test01 = array('a' => 'aaaa', 'b' => 'bbbb', 'c' => 'cccc');
foreach ($test01 as $key => $value) {
echo "$key => $value";
}
$test01 = array('a' => 'aaaa', 'b' => 'bbbb', 'c' => 'cccc');
while (list($key, $value) = each($test01)) {
echo "$key => $value" . "<br/>";
}
php中,迭代遍历主要要用到以下函数。
current() 迭代的当前元素。
reset() 重新移动到第一个元素并返回它。
next() 移动到下一个元素并返回它。
prev() 移动到上一个元素并返回它。
end() 移动到最后一个元素并返回它。
each() 以数组的形式返回当前元素的索引和值,并移动到下一个迭代。
key() 返回当前的索引。
array_ walk() 为每一个元素调用函数。
array_ reduce() 为每一个元素依次计算。
变通遍历
array_walk($test01, walk_test);
function walk_test($key, $value) {
echo "walk: $key => $value" . "<br/>";
}
$test02 = array(1, 2, 3, 4, 5);
echo array_reduce($test02, reduce_test);
function reduce_test($run_result, $current_value) {
return $run_result + $current_value * $current_value;
}