当前位置: 编程技术>php
本页文章导读:
▪php正则匹配重写html图片img路径的代码一例 1、正则写法:
<?php
$str = <<<EOF
<img src="/blog_article/uploads/images/20100318/20100318_1.gif">
<img src="/blog_article/file/20100318_2.jpg">
<img src="/blog_article/swfup/20100318_3.png">
EOF;
echo '替换前:<pre>',htmlentities($str),'<.........
▪php简单页面缓存的实现代码 代码如下:
<?php
/*
* php 简单缓存
* by http://www.
**/
// define the path and name of cached file
$cachefile = 'cached-files/'.date('M-d-Y').'.php';
// define how long we want to keep the file in seconds. I set mi.........
▪php计算距离的代码一例 代码如下:
<?php
/**
* 根据经纬度计算距离
* by http://www.
*/
function distance($lat1, $lon1, $lat2, $lon2, $unit) {
$theta = $lon1 - $lon2;
$dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos.........
[1]php正则匹配重写html图片img路径的代码一例
来源: 互联网 发布时间: 2013-12-24
1、正则写法:
<?php $str = <<<EOF <img src="/blog_article/uploads/images/20100318/20100318_1.gif"> <img src="/blog_article/file/20100318_2.jpg"> <img src="/blog_article/swfup/20100318_3.png"> EOF; echo '替换前:<pre>',htmlentities($str),'</pre><hr align=left width=320px/>'; echo '替换后:<pre>',htmlentities(preg_replace('/(<img.+?src="/blog_article/)[^/index.html"]+(\/.+?>)/', '$1file$2', $str)),'</pre>'; ?>
2、替换操作
替换前:
代码示例:
<img src="/blog_article/uploads/images/20100318/20100318_1.gif">
<img src="/blog_article/file/20100318_2.jpg">
<img src="/blog_article/swfup/20100318_3.png">
<img src="/blog_article/file/20100318_2.jpg">
<img src="/blog_article/swfup/20100318_3.png">
替换后:
代码示例:
<img src="/blog_article/file/20100318_1.gif">
<img src="/blog_article/file/20100318_2.jpg">
<img src="/blog_article/file/20100318_3.png">
<img src="/blog_article/file/20100318_2.jpg">
<img src="/blog_article/file/20100318_3.png">
您可能感兴趣的文章:
php匹配图片地址的代码一例
PHP正则匹配日期和时间(时间戳转换)的例子
php匹配任何网址的正则表达式
PHP正则匹配获取URL中域名的代码
使用 preg_replace 函数 匹配图片并加上链接的方法
php用preg_match_all匹配文章中的图片
php正则表达式匹配URL中的域名
[2]php简单页面缓存的实现代码
来源: 互联网 发布时间: 2013-12-24
代码如下:
<?php /* * php 简单缓存 * by http://www. **/ // define the path and name of cached file $cachefile = 'cached-files/'.date('M-d-Y').'.php'; // define how long we want to keep the file in seconds. I set mine to 5 hours. $cachetime = 18000; // Check if the cached file is still fresh. If it is, serve it up and exit. if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile)) { include($cachefile); exit; } // if there is either no file OR the file to too old, render the page and capture the HTML. ob_start(); ?> <html> output all your html here. </html> <?php // We're done! Save the cached content to a file $fp = fopen($cachefile, 'w'); fwrite($fp, ob_get_contents()); fclose($fp); // finally send browser output ob_end_flush(); ?>
查看详细:http://wesbos.com/simple-php-page-caching-technique/
您可能感兴趣的文章:
php缓存函数简介
一个php网站缓存代码分享
php页面缓存ob系列函数的相关介绍
php禁止页面缓存的代码
有关php的缓存技术介绍
一个php的页面缓存类
一个php禁止页面缓存的函数
细说PHP下的缓存技术
[3]php计算距离的代码一例
来源: 互联网 发布时间: 2013-12-24
代码如下:
<?php /** * 根据经纬度计算距离 * by http://www. */ function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper()($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } //调用示例 echo distance(32.9697, -96.80322, 29.46786, -98.53506, "k")." kilometers"; ?>
最新技术文章: