asp教程/asp.net教程/php教程实现301重定向代码,一般我们做301是全用iis,apache来实现,在没有操作服务器的时我们再用脚本来实现,代码如下。
1、asp下的301重定向代码
<%@ language=vbscript %>
<%
response.status=”301 moved permanently”
response.addheader “location”, “106/”
%>
2、asp.net下的301重定向代码
<script runat=”server”>
private void page_load(object sender, system.eventargs e)
{
response.status = “301 moved permanently”;
response.addheader(”location”,” 106/“);
}
</script>
3、php下的301重定向代码
header(”http/1.1 301 moved permanently”);
header(”location: 106/”);
exit();
第一行代码是强制下载;
第二行代码是给下载的内容指定一个名字;
第三行代码是把下载的内容读进文件中。
提示用户保存一个生成的 pdf 文件(content-disposition 报头用于提供一个推荐的文件名,并强制浏览器显示保存对话框):
<?php教程2 header("content-type: application/force-download");
3 header("content-disposition: attachment; filename=ins.jpg");
4 readfile("imgs/test_zoom.jpg");
5 ?>
header() 函数向客户端发送原始的 http 报头。
认识到一点很重要,即必须在任何实际的输出被发送之前调用 header() 函数(在 php 4 以及更高的版本中,您可以使用输出缓存来解决此问题):
header(string,replace,http_response_code)
其它用法
<?php
// date in the past
header("expires: mon, 26 jul 1997 05:00:00 gmt");
header("cache-control: no-cache");
header("pragma: no-cache");
?>
$string = "this is a test";
echo str_replace(" is", " was", $string);
echo ereg_replace("( )is", "1was", $string); 其中1就是第一个括号中空格
echo ereg_replace("(( )is)", "2was", $string); 其中2就是第二个括号的空格
上面三行也就是把" is"替换为" was";都有空格的。
ereg_replace ( string pattern, string replacement, string string)
也就是说如果pattern中带有()得字符串(如;括号中有空格),那你的replacement就可以使用如1的字符串,那这个1就给可以用你第1个括号中字符串来替换,如果是2那就用第2个括号中的字符串替换.
括号从左到右,以左括号为准.
下面那个是去掉url中的如&page=1
符串比对解析并取代。
语法: string ereg_replace(string pattern, string replacement, string string);
返回值: 字符串
函数种类: 资料处理
内容说明
本函数以 pattern 的规则来解析比对字符串 string,欲取而代之的字符串为参数 replacement。返回值为字符串类型,为取代后的字符串结果。
使用范例
ken@freebsdrocks.com 在 16-mar-1999 提出的例子。
<?php教程
$text = 'this is a {1} day, not {2} and {3}.';
$daytype = array( 1 => 'fine',
2 => 'overcast',
3 => 'rainy' );
while (ereg ('{([0-9]+)}', $text, $regs)) {
$found = $regs[1];
$text = ereg_replace("{".$found."}", $daytype[$found], $text);
}
echo "$textn";
// this is a fine day, not overcast and rainy.
?>
ken@freebsdrocks.com 并同时提出具有相同功能的perl 程序范例如下:
$text = 'this is a {1} day, not {2} and {3}.';
%daytype = ( 1 => 'fine',
2 => 'overcast',
3 => 'rainy' );
$text =~ s/{(d+)}/$daytype{$1}/eg;
print "$textn";
php教程 效率的字符串处理方法
<?php
$str = array(
"helloworld",
"howareyou",
"cpufrequency",
"windows7ready",
"newedition2",
"downloadurllist",
"heisasuperhero",
);//你的解决方法
/*
正确添加空格后应为:
"helloworld" = "hello world"
"howareyou" = "how are you"
"cpufrequency" = "cpu frequency"
"windows7ready" = "windows 7 ready"
"newedition2" = "new edition 2"
"downloadurllist" = "download url list"
"heisasuperhero" = "he is a super hero"
*/?>
程序代码
function transfer($input) {
$newarray = array();
foreach($input as $i) {
$arr = str_split($i);
$word = '';
foreach($arr as $a) {
$ascii = ord($a);
$lastword = substr($word, -1);
$ascii_1 = ord($lastword);
$lastword_ = substr($word, -2, 1);
if($ascii > 64 && $ascii < 91) {
if($ascii_1 > 96 && $ascii_1 < 122) {
$word .= ' '.$a;
} else {
$word .= $a;
}
} elseif($ascii > 96 && $ascii < 122) {
if($ascii_1 > 64 && $ascii_1 < 91) {
if(strlen($word) == 1) {
$word .= $a;
} else {
if(ord($lastword_) == 32) {
$word .= $a;
} else {
$word = substr($word, 0, -1).' '.$lastword.$a;
}
}
} else {
$word .= $a;
}
} else {
if(strlen($word) == 0) {
$word .= $a;
} else {
$word .= ' '.$a;
}
}
}
$newarray[$i] = $word;
}
return $newarray;
}print_r(transfer($str));
在php教程使用curl时必须先在php.ini中开启extension=php_curl.dll前面的;去了,才行哦,curl是php中一款内置的浏览器,它可以模仿用户浏览信息进行网站浏览,等下面来看一实例。
function postpage($url)
{
$response = "";
$rd=rand(1,4);
$proxy='http://221.214.27.253:808';
if($rd==2) $proxy='http://222.77.14.56:8088';
if($rd==3) $proxy='http://202.98.123.126:8080';
if($rd==4) $proxy='http://60.14.97.38:8080';
if($url != "") {
$ch = curl_init($url);
curl_setopt($ch, curlopt_header, 0);
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_proxy, $proxy);
$response = curl_exec($ch);
if(curl_errno($ch)) $response = "";
curl_close($ch);
}
return $response;
}
curl包括部份函数
curl_close — close a curl session
curl_copy_handle — copy a curl handle along with all of its preferences
curl_errno — return the last error number
curl_error — return a string containing the last error for the current session
curl_exec — perform a curl session
curl_getinfo — get information regarding a specific transfer
curl_init — initialize a curl session
curl_multi_add_handle — add a normal curl handle to a curl multi handle
curl_multi_close — close a set of curl handles
curl_multi_exec — run the sub-connections of the current curl handle
curl_multi_getcontent — return the content of a curl handle if curlopt_returntransfer is set
curl_multi_info_read — get information about the current transfers
curl_multi_init — returns a new curl multi handle
curl_multi_remove_handle — remove a multi handle from a set of curl handles
curl_multi_select — wait for activity on any curl_multi connection
curl_setopt_array — set multiple options for a curl transfer
curl_setopt — set an option for a curl transfer
curl_version — gets curl version information