制定input几种type的样式

网页设计 No Comments

做一个页面的时候,我自己没有对input的几种样式,指定class

我觉得一般比较正确的做法是,指定这个input的class name 或者id name

在方便的在css文件中修改它的样式

我现在要说的是,没有指定的情况下怎么改变样式

如果你在css中写,例如

1
2
3
4
5
input{
	font: 9pt Tahoma, Verdana;
	font-weight: normal;
	background: #ECF1F7;
}

你会发现,不管是输入框text模式还是按钮(submit方式)
背景都变成一样了。

怎么样只对比如input type=”text”的样式进行制定呢?
我发现这样可以

1
2
3
input[type=text]{
border: 1px solid #cccccc;
}

这样你就发现,按钮的样式没有跟随改变,但是text的边框已经变化了~

这个在ie 7.0 测试通过

其他不晓得~~

呵呵

 

php获得远程文件大小的函数

php技巧 1 Comment

 文件的大小函数为:filesize()
文件是否存在的函数为:file_exits();
但是这两个函数只针对本地

那么:远程文件是否存在,远程文件大小 如何得知呢?

搜索了一下,有人居然说,把远程文件下载过来再判断这个远程文件的大小,这是什么歪理。

庆幸大部分人还是清醒的,一般应该使用判断header反馈的信息进行判断。

php中如何获得header信息呢? php的函数真多,这个也不例外

1.最简单的获取远程文件大小办法

1
$a_array = get_headers(url,true);

url就是网址了,至于第二个参数

就可以得到类似下面的这个数组

1
2
3
4
5
6
7
8
9
10
11
12
Array
(
    [0] => HTTP/1.1 200 OK
    [Date] => Sat, 29 May 2004 12:28:14 GMT
    [Server] => Apache/1.3.27 (Unix)  (Red-Hat/Linux)
    [Last-Modified] => Wed, 08 Jan 2003 23:11:55 GMT
    [ETag] => "3f80f-1b6-3e1cb03b"
    [Accept-Ranges] => bytes
    [Content-Length] => 438
    [Connection] => close
    [Content-Type] => text/html
)

所以,你可以很舒服的拿到远程文件的大小

1
$file_sizeofurl = a_array['Content-Length'];

2.用curl获取远程文件大小
如果服务器禁止get_headers 怎么办?
换一种办法,用curl
我总觉得curl就像一个虚拟的用户,什么都能模仿

下面直接给出一个老外的函数
请注意

1
echo '<br>head-->'.$head.'<----end <br>';

这句是我加的,为了知道header里面到底包含了什么东西

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function remote_filesize($uri,$user='',$pw='') 
{ 
// start output buffering 
ob_start(); 
// initialize curl with given uri 
$ch = curl_init($uri); 
// make sure we get the header 
curl_setopt($ch, CURLOPT_HEADER, 1); 
// make it a http HEAD request 
curl_setopt($ch, CURLOPT_NOBODY, 1); 
// if auth is needed, do it here 
if (!empty($user) && !empty($pw)) 
{ 
$headers = array('Authorization: Basic ' . base64_encode($user.':'.$pw)); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
} 
$okay = curl_exec($ch); 
curl_close($ch); 
// get the output buffer 
$head = ob_get_contents(); 
// clean the output buffer and return to previous 
// buffer settings 
ob_end_clean(); 
 
echo '<br>head-->'.$head.'<----end <br>';
 
// gets you the numeric value from the Content-Length 
// field in the http header 
$regex = '/Content-Length:\s([0-9].+?)\s/'; 
$count = preg_match($regex, $head, $matches); 
 
// if there was a Content-Length field, its value 
// will now be in $matches[1] 
if (isset($matches[1])) 
{ 
$size = $matches[1]; 
} 
else 
{ 
$size = 'unknown'; 
} 
//$last=round($size/(1024*1024),3); 
//return $last.' MB'; 
return $size;
}

3.fsock获取远程文件大小的办法
先给函数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function getFileSize($url){ 
        $url = parse_url($url);
        if($fp = @fsockopen($url['host'],empty($url['port'])?80:$url['port'],$error)){
                fputs($fp,"GET ".(empty($url['path'])?'/':$url['path'])." HTTP/1.1\r\n");
                fputs($fp,"Host:$url[host]\r\n\r\n");
                while(!feof($fp)){
                        $tmp = fgets($fp);
                        if(trim($tmp) == ''){
                                break;
                        }else if(preg_match('/Content-Length:(.*)/si',$tmp,$arr)){
                                return trim($arr[1]);
                        }
                }
                return null;
        }else{
                return null;
        }
}

哪个获取远程文件大小最快?
针对同一个url进行测试,curl > fsock > getheader
针对不同url测试,结果还是 curl > fsock > getheader
当然也许这个测试是不准确的,但getheader函数是明显要慢一些的

考虑到curl模块没有fsock那么普及,所以我自己还是用后面一个

速度上的差别大约是 curl比fsock快0.2秒,fsock比getheader快0.2秒。

远程文件的大小拿来干嘛用?
好像某些人用来分块下载文件
我是拿来判断远程文件是否更新(虽然不准),其他人有什么好办法不?给我留言吧

网站的email地址怎么处理

网页设计 3 Comments

今天浏览一个老外的网站发现,老外对网站联系人的email经过了处理,我觉得也挺方便

一般而言,最差的方式是,

直接留email,比如网页最底下写上:supports@163.com

这个很容易就被别人搜集到,肯定不行,过不了多久,你的邮箱就是一堆的垃圾邮件了

我这样处理

1.把email地址做成图片,优点是不会被采集到,而且图片是“国际语言”不会乱码,缺点是更改比较麻烦

注:有读取图片文字的软件,只不过能用软件读取你的网站email地址,无异于脱了裤子放屁。。。

2.还有就是老外的这个办法了,他写到js里,也挺方面,省去了制作图片,而且容易更改内容

老外是调用一个mail.js文件

1
<script src="mail.js" type="text/javascript"></script>

文件的内容是:

1
2
3
4
5
6
7
8
9
10
document.write('<a href="');
document.write('mailto:');
document.write('serg036');
document.write('@');
document.write('gmail.com');
document.write('">');
document.write('serg036');
document.write('{at}');
document.write('gmail.com');
document.write('</a>');

 为什么要一行一行的写?

为什么不这样写:

1
document.write('<a href="mailto:serg036@gmail.com">serg036{at}gmail.com</a>');

我猜测是躲避搜索引擎,谣传搜索引擎是能读懂简单的js的

没做过实验,有兴趣的朋友可以试试,把实验结果告诉我,我公布公布

呵呵

俺是phper

Uncategorized No Comments

一个初学php的学童~~

以后写写日记啥的

 

呵呵

Icons by N.Design Studio. Designed By Ben Swift. Powered by WordPress and Free WordPress Themes
Entries RSS Comments RSS Log in