分类目录 ‘程序源码’

I-nfotech 有一篇文章列出十個每一個 PHP 開發者都應該認識的開發項目, 我們都知道 擁有全世界最龐大的原碼程式庫(不知道的話現在仍不算遲),所以在開發過程中幾乎所有你需要的功能都已經有人寫好了,你只需插入你的項目中便可以使用,文章的作者有多年的網頁開發經驗,他總結多年的心得,列出了十個每一個 開發者都應該認識的 函式庫。你的要求可能不同,但這篇文章的內容仍然很值得參考。
(全文 …)

  1. var Url = location.href;
  2. Url = Url.replace(/.*\?(.*?)/,”$1″);
  3. Variables = Url.split (“&”);
  4. for (i = 0; i < Variables.length; i++) {
  5. Separ = Variables[i].split(“=”);
  6. eval (‘var ‘+Separ[0]+’=”‘+Separ[1]+’”‘);
  7. }
  8. function getURLParam(strParamName){
  9. var strReturn = “”;
  10. var strHref = window.location.href;
  11. if ( strHref.indexOf(“?”) > -1 ){
  12. var strQueryString = strHref.substr(strHref.indexOf(“?”)).toLowerCase();
  13. var aQueryString = strQueryString.split(“&”);
  14. for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
  15. if (aQueryString[iParam].indexOf(strParamName + “=”) > -1 ){
  16. var aParam = aQueryString[iParam].split(“=”);
  17. strReturn = aParam[1];
  18. break;
  19. }
  20. }
  21. }
  22. return strReturn;
  23. }

使用PHP自动生成密码

In this tutorial I will show you how to generate random passwords that are highly secure and extremely difficult to crack. However you can choose between various complexity/strength and you can set password length as well.

Step 1.

Let’s go through what we need to generate passwords. First we need a list of words and/or characters what we can use for password generation. I don’t offer using word lists as it is easier to guess and password recovery tools are using such lists as well. So I will focus only on character lists.

The idea is to create a string from the characters and than in a loop we select an item from this string (character list) one by one until we reach the requested length. To realize this we will implement a function with 2 parameters. The first is the length of the requested password and the second is the strength/complexity of the password.
(全文 …)

最早发现这个时差问题是在我们首页添加24小时内热文(显示浏览最多十篇文章)后发现的,平时每天更新20-30篇,即 使扣除8小时影响也不大,但在某个周末的最近24小时文章刚好够10篇时,它只显示几篇给我,当时就诧异了。当时没想过根源是 timestamp 函数,只是想简单 hack 一下就好,将 wp-postviews 插件里 get_timespan_most_viewed 函数中的

$limit_date = current_time(’timestamp’) – ($days*86400);

改为

$limit_date = current_time(’timestamp’) – ($days*86400) – 28800;

// 8小时就是 8×60×60=28800秒

所以今天在把我们首页第一篇文章的时间显示方式改为 xxx mins ago 时,8小时时差又出现了,于是毫不犹豫的暴力 hack 了,同样是把

<? echo human_time_diff(get_the_time(’U’), current_time(’timestamp’)) . ‘ ago’; ?>

改成

<?php echo human_time_diff(get_the_time(’U’), current_time(’timestamp’) – 28800 ) . ‘ ago’; ?>

当然我这样指标不治本,有兴趣折腾的同学可以直接到 wp-includes/formatting.php 里修改 human_time_diff。就解决 human_time_diff 函数的 timezone 问题而言,我这个方法简单有效(网上N多老外哭求这个时差问题都没有答案,哈哈哈),但究其根源还是要解决 timestamp 函数的时差问题。
(全文 …)

前言:最近使用到了他人总结的一个基础类库。查看了下源码,发现String帮助类的一个辅助方法不是很严谨,重构之。

1、原来程序的写法

      public static string GetDomainName(string url)
        {
            Regex reg = new Regex(@"http(s)?://([\w-]+\.)+[\w-]+/?");
            string result = reg.Match(url, 0).Value;
            if (result.IndexOf("http://") > -1)
            {
                result = result.Replace("http://", string.Empty);
            }
            else if (result.IndexOf("https://") > -1)
            {
                result = result.Replace("https://", string.Empty);
            }
            return result.Replace("/", string.Empty);
        }

(全文 …)

 

jQuery除了选择器之外,还封装了很多事件的处理,比如鼠标事件,所谓 的鼠标事件是指用户在移动鼠标光标或者点击任意鼠标键而触发的事件,jQuery中封装了几乎所有的鼠标事件,包括点击,双击,移出,移入等鼠标事件,下 面断桥残雪简单的介绍下jQuery的鼠标事件

jQuery的click事件

经典鼠标click的实例:

$("sel").click(function(){
    alert('哈哈 !');
});

(全文 …)

这里提供一些javascript检测代码,用于检测iPhone、iPod、iPad设备。

// Apple detection object
var Apple = {};
Apple.UA = navigator.userAgent;
Apple.Device = false;
Apple.Types = ["iPhone", "iPod", "iPad"];
for (var d = 0; d < Apple.Types.length; d++) {
var t = Apple.Types[d];
Apple[t] = !!Apple.UA.match(new RegExp(t, “i”));
Apple.Device = Apple.Device || Apple[t];
}
// is this an Apple device?
alert(
“Apple device? ” + Apple.Device +
“\niPhone? ” + Apple.iPhone +
“\niPod? ” + Apple.iPod +
“\niPad? ” + Apple.iPad
);
也可以使用类似的PHP代码在服务器端检测,具体方法可以查看How to Identify an Apple iPhone, iPod or iPad Visitor to Your Website

<?
/**
* 生成缩略图
*
* @param string $imagePath 图片路径
* @param string $thumb 生成缩略图名称
* @param integer $width 生成缩略图最大宽度
* @param integer $height 生成缩略图最大高度
*
* @author Silver
* @link http://www.zdyi.com
*/
function resizeImage($imagePath, $thumb, $width = 200, $height = 200)
{
list($imageWidth, $imageHeight) = getimagesize($imagePath);
$imagePath = imagecreatefromjpeg($imagePath);
if ($width && ($imageWidth < $imageHeight))
{
$width = ($height / $imageHeight) * $imageWidth;
}
else
{
$height = ($width / $imageWidth) * $imageHeight;
}
$image = imagecreatetruecolor($width, $height);
imagecopyresampled($image, $imagePath, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
imagepng($image, $thumb);
imagedestroy($image);
}
resizeImage('test.jpg', 'test_thumb.jpg');
?>

罪恶的IE6不支持max-height属性,不过我们可以通过jQuery来解决IE6不支持max- height,的代码如下:

$(".entry").each(function(){
    if($(this)[0].scrollHeight&gt;500)
     $(this).css({"height":"500px"});
});

原理: 在IE6中可以通过设定height来达到max-height的 效果. 循环所有要加max-height属性的DOM元素,判断他的scrollHeight大于你要设置的最大高度 如果超过了就通过设置height为最大高度,我这里使用的是[0],获取的是的DOM对象,而不是jQuery对象,详细说明见:《jQuery选择器使用详解》
(全文 …)