当前位置: 编程技术>php
本页文章导读:
▪php查找、替换字符串中http地址的代码分享 在字符串中查找、替换http地址,代码如下:
<?php
/**
* 查找、替换字符串http地址
* edit by www.
*/
function convertImg($str)
{
$str = preg_replace("/\{([^}]+)\}/",'<div style="border:1px dashed #003366;
.........
▪php记录搜索引擎关键词的代码示例 用php实现记录搜索引擎搜索关键词,代码如下:
<?php
/**
* 记录搜索引擎搜索关键词
* edit by www.
*/
//搜索来源
$rfr = $_SERVER['HTTP_REFERER'];
//if(!$rfr) $rfr='http://'.$_SERVER['HTTP_HOST'];
if($rfr.........
▪php实现gzip压缩html数据的代码 代码如下:
<?php
/**
* gzip压缩html数据
* edit by www.
*/
ob_start("ob_gzhandler");
ob_start("compress"); //开启压缩
header("Content-type: text/Css; charset: UTF-8");
header("Cache-Control: must-revalidate");
$.........
[1]php查找、替换字符串中http地址的代码分享
来源: 互联网 发布时间: 2013-12-24
在字符串中查找、替换http地址,代码如下:
<?php
/**
* 查找、替换字符串http地址
* edit by www.
*/
function convertImg($str)
{
$str = preg_replace("/\{([^}]+)\}/",'<div style="border:1px dashed #003366;
background-color:#f0f0f0; height:21px; color:#003399">回复:$1</div>',preg_replace("/\[(\d+)\]/",
'<img src="/images/face/face$1.jpg"/>',$str));
$reg="/http\:\/\/(\w+\.)+(net|com|org|cn|kr|jp|tw)[A-Za-z0-9_&\/\?=]*/i";
if(preg_match_all($reg,$str,$out))
{
for($i=0;$i<count($out[0]);$i++)
{
$link=substr(base64_encode(md5(preg_replace("/http\:\/\//","",$out[0][$i]))),0,10+strlen($str)%10);
$str=str_replace($out[0][$i],'<a href="'.$out[0][$i].'">http://'.$link.'</a>',$str);
}
}
return $str;
}
?>
[2]php记录搜索引擎关键词的代码示例
来源: 互联网 发布时间: 2013-12-24
用php实现记录搜索引擎搜索关键词,代码如下:
<?php
/**
* 记录搜索引擎搜索关键词
* edit by www.
*/
//搜索来源
$rfr = $_SERVER['HTTP_REFERER'];
//if(!$rfr) $rfr='http://'.$_SERVER['HTTP_HOST'];
if($rfr)
{
$p=parse_url(/blog_article/$rfr/index.html);
parse_str($p['query'],$pa);
$p['host']=strtolower($p['host']);
$arr_sd_key=array(
'baidu.com'=>'word',
'google.com'=>'q',
'sina.com.cn'=>'word',
'sohu.com'=>'word',
'msn.com'=>'q',
'bing.com'=>'q',
'163.com'=>'q',
'yahoo.com'=>'p'
);
$keyword='';
$sengine=$p['host'];
foreach($arr_sd_key as $se=>$kwd)
{
if(strpos($p['host'],$se)!==false)
{
$keyword=$pa[$kwd];
$sengine=$se;
break;
}
}
//写入搜索日志
$sql="insert into visit_log(domain,key_word,ct)";
}
?>
代码很简单,主要是给大家一个思路:
通过分析搜索引擎来源,截取url中的相关参数值,继而分析出关键词,匹配好有关的搜索,并记录进搜索日志数据库中。
更多有关记录搜索引擎关键词的文章,请参考:
php获取搜索引擎入站关键词的函数
php记录搜索引擎来路及关键词的实现代码
php获取各搜索蜘蛛爬行记录的代码
php搜索并显示关键字的例子
php获取搜索引擎关键字来源(支持百度、谷歌等搜索引擎)的函数
[3]php实现gzip压缩html数据的代码
来源: 互联网 发布时间: 2013-12-24
代码如下:
<?php
/**
* gzip压缩html数据
* edit by www.
*/
ob_start("ob_gzhandler");
ob_start("compress"); //开启压缩
header("Content-type: text/Css; charset: UTF-8");
header("Cache-Control: must-revalidate");
$off = 0; # Set to a reaonable value later, say 3600 (1 hr);
$exp = "Expires: " . gmdate("D, d M Y H:i:s", time() + $off) . " GMT";
header($exp);
function compress($buffer) {
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer); // remove comments
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer); // remove tabs, spaces, newlines, etc.
$buffer = str_replace('{ ', '{', $buffer); // remove unnecessary spaces.
$buffer = str_replace(' }', '}', $buffer);
$buffer = str_replace('; ', ';', $buffer);
$buffer = str_replace(', ', ',', $buffer);
$buffer = str_replace(' {', '{', $buffer);
$buffer = str_replace('} ', '}', $buffer);
$buffer = str_replace(': ', ':', $buffer);
$buffer = str_replace(' ,', ',', $buffer);
$buffer = str_replace(' ;', ';', $buffer);
return $buffer;
}
require_once('screen.css');
require_once('layout.css');
require_once('custom.php');
require_once('titles.css');
require_once('bus.css');
?>
有兴趣的朋友,可以百度下检测gzip压缩效果的工具或网站,看看压缩比率如何!
最新技术文章: