当前位置: 编程技术>php
本页文章导读:
▪php array_merge下进行数组合并的代码
如 $array3=array("性别"=>"男","姓名"=>"不是女人"); $array4=array("性别"=>"不知道","长相"=>"很帅"); 哪么,合并之后,后者将会覆盖前者,这样合并之后就变成了 Array ( [性别] => .........
▪用php过滤危险html代码的函数
#用户发布的html,过滤危险代码 function uh($str) { $farr = array( "/\\s+/", //过滤多余的空白 "/<(\\/?)(scrīpt|i?frame|style|html|body|title|link|meta|\\?|\\%)([^>]*?)>/isU", //过滤 <scrīpt 等可能.........
▪php socket方式提交的post详解
<? /* ** POST报文到主机 */ function PostToHost($url, $data) { $url = parse_url(/blog_article/$url/index.html); if (!$url) return "couldn\'t parse url"; if (!isset($url[\'port\'])) { $url[\'port\'] = ""; } if (!isset($url[\'query\']).........
[1]php array_merge下进行数组合并的代码
来源: 互联网 发布时间: 2013-11-30
如
$array3=array("性别"=>"男","姓名"=>"不是女人");
$array4=array("性别"=>"不知道","长相"=>"很帅");
哪么,合并之后,后者将会覆盖前者,这样合并之后就变成了
Array ( [性别] => 不知道 [姓名] => 不是女人 [长相] => 很帅 )
数字型键名,或自动赋值键名,则不会产生覆盖,
如
$array1=array(1,2,3,4,5,6,7);
$array2=array(1,7,8,9,10);
合并之后,为
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 1 [8] => 7 [9] => 8 [10] => 9 [11] => 10 )
$array3=array("性别"=>"男","姓名"=>"不是女人");
$array4=array("性别"=>"不知道","长相"=>"很帅");
哪么,合并之后,后者将会覆盖前者,这样合并之后就变成了
Array ( [性别] => 不知道 [姓名] => 不是女人 [长相] => 很帅 )
数字型键名,或自动赋值键名,则不会产生覆盖,
如
$array1=array(1,2,3,4,5,6,7);
$array2=array(1,7,8,9,10);
合并之后,为
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 [5] => 6 [6] => 7 [7] => 1 [8] => 7 [9] => 8 [10] => 9 [11] => 10 )
[2]用php过滤危险html代码的函数
来源: 互联网 发布时间: 2013-11-30
#用户发布的html,过滤危险代码
function uh($str)
{
$farr = array(
"/\\s+/", //过滤多余的空白
"/<(\\/?)(scrīpt|i?frame|style|html|body|title|link|meta|\\?|\\%)([^>]*?)>/isU", //过滤 <scrīpt 等可能引入恶意内容或恶意改变显示布局的代码,如果不需要插入flash等,还可以加入<object的过滤
"/(<[^>]*)on[a-zA-Z]+\\s*=([^>]*>)/isU", //过滤javascrīpt的on事件
);
$tarr = array(
" ",
"<\\\\1\\\\2\\\\3>", //如果要直接清除不安全的标签,这里可以留空
"\\\\1\\\\2",
);
$str = preg_replace( $farr,$tarr,$str);
return $str;
}
function uh($str)
{
$farr = array(
"/\\s+/", //过滤多余的空白
"/<(\\/?)(scrīpt|i?frame|style|html|body|title|link|meta|\\?|\\%)([^>]*?)>/isU", //过滤 <scrīpt 等可能引入恶意内容或恶意改变显示布局的代码,如果不需要插入flash等,还可以加入<object的过滤
"/(<[^>]*)on[a-zA-Z]+\\s*=([^>]*>)/isU", //过滤javascrīpt的on事件
);
$tarr = array(
" ",
"<\\\\1\\\\2\\\\3>", //如果要直接清除不安全的标签,这里可以留空
"\\\\1\\\\2",
);
$str = preg_replace( $farr,$tarr,$str);
return $str;
}
[3]php socket方式提交的post详解
来源: 互联网 发布时间: 2013-11-30
<?
/*
** POST报文到主机
*/
function PostToHost($url, $data) {
$url = parse_url(/blog_article/$url/index.html);
if (!$url) return "couldn\'t parse url";
if (!isset($url[\'port\'])) { $url[\'port\'] = ""; }
if (!isset($url[\'query\'])) { $url[\'query\'] = ""; }
$encoded = "";
while (list($k,$v) = each($data)) {
$encoded .= ($encoded ? "&" : "");
$encoded .= rawurlencode($k)."=".rawurlencode($v);
}
$port = $url[\'port\'] ? $url[\'port\'] : 80;
$fp = fsockopen($url[\'host\'], $port, $errno, $errstr);
if (!$fp) return "Failed to open socket to $url[host] $port ERROR: $errno - $errstr";
fputs($fp, sprintf("POST %s%s%s HTTP/1.0\\n", $url[\'path\'], $url[\'query\'] ? "?" : "", $url[\'query\']));
fputs($fp, "Host: $url[host]\\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\\n");
fputs($fp, "Content-length: " . strlen($encoded) . "\\n");
fputs($fp, "Connection: close\\n\\n");
fputs($fp, "$encoded\\n");
$line = fgets($fp,1024);
if (!eregi("^HTTP/1\\.. 200", $line)) return;
$results = ""; $inheader = 1;
while(!feof($fp)) {
$line = fgets($fp,1024);
if ($inheader && ($line == "\\n" || $line == "\\r\\n")) {
$inheader = 0;
}
elseif (!$inheader) {
$results .= $line;
}
}
fclose($fp);
return $results;
}/* end function PostToHost */
?>
/*
** POST报文到主机
*/
function PostToHost($url, $data) {
$url = parse_url(/blog_article/$url/index.html);
if (!$url) return "couldn\'t parse url";
if (!isset($url[\'port\'])) { $url[\'port\'] = ""; }
if (!isset($url[\'query\'])) { $url[\'query\'] = ""; }
$encoded = "";
while (list($k,$v) = each($data)) {
$encoded .= ($encoded ? "&" : "");
$encoded .= rawurlencode($k)."=".rawurlencode($v);
}
$port = $url[\'port\'] ? $url[\'port\'] : 80;
$fp = fsockopen($url[\'host\'], $port, $errno, $errstr);
if (!$fp) return "Failed to open socket to $url[host] $port ERROR: $errno - $errstr";
fputs($fp, sprintf("POST %s%s%s HTTP/1.0\\n", $url[\'path\'], $url[\'query\'] ? "?" : "", $url[\'query\']));
fputs($fp, "Host: $url[host]\\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\\n");
fputs($fp, "Content-length: " . strlen($encoded) . "\\n");
fputs($fp, "Connection: close\\n\\n");
fputs($fp, "$encoded\\n");
$line = fgets($fp,1024);
if (!eregi("^HTTP/1\\.. 200", $line)) return;
$results = ""; $inheader = 1;
while(!feof($fp)) {
$line = fgets($fp,1024);
if ($inheader && ($line == "\\n" || $line == "\\r\\n")) {
$inheader = 0;
}
elseif (!$inheader) {
$results .= $line;
}
}
fclose($fp);
return $results;
}/* end function PostToHost */
?>
最新技术文章: