Îļþ¶ÁÈ¡º¯Ê½
//Îļþ¶ÁÈ¡º¯Ê½
function PHP_Read($file_name) {
$fd=fopen($file_name,r);
while($bufline=fgets($fd, 4096)){
$buf.=$bufline;
}
fclose($fd);
return $buf;
}
?>
ÎļþдÈ뺯ʽ
//ÎļþдÈ뺯ʽ
function PHP_Write($file_name,$data,$method="w") {
$filenum=@fopen($file_name,$method);
flock($filenum,LOCK_EX);
$file_data=fwrite($filenum,$data);
fclose($filenum);
return $file_data;
}
?>
¾²Ì¬Ò³ÃæÉú³Éº¯Ê½
//¾²Ì¬Ò³ÃæÉú³Éº¯Ê½
function phptohtm($filefrom,$fileto,$u2u=1){
if($u2u==1){
$data=PHP_Read($filefrom);
}else{
$data=$filefrom;
}
PHP_Write($fileto,$data);
return true;
& ......
ÈçºÎÅжÏipµØÖ·ºÏ·¨ÐÔ
if(!strcmp(long2ip(sprintf("%u",ip2long($ip))),$ip)) echo "is ipn";
emailµÄÕýÔòÅжÏ
eregi("^[_.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z_-]+.)+[a-zA-Z]$", $email);
¼ì²âipµØÖ·ºÍmaskÊÇ·ñºÏ·¨µÄÀý×Ó
$ip = '192.168.0.84';
$mask = '255.255.255.0';
$network = '192.168.0';
$ip = ip2long($ip);
$mask = ip2long($mask);
$network = ip2long($network);
if( ($ip & $mask) == $network) echo "valid ip and maskn";
?>
ÎļþÏÂÔØÍ·²¿Êä³öÈçºÎÉ趨
header("Content-type: application/x-download");
header("Content-Disposition: attachment; filename=$file_download_name;");
header("Accept-Ranges: bytes");
header("Content-Length: $download_size");
echo 'xxx'
ÓÃheaderÊä³öftpÏÂÔØ·½Ê½,²¢ÇÒÖ§³Ö¶ÏµãÐø´«
Ò»¸öÀý×Ó:
header('Pragma: public');
header('Cache-Control: private');
header('Cache-Control: no-cache, must-revalidate');
header('Accept-Ranges: bytes');
header('Connection: close');
header("Content-Type: audio/mpeg");
header("Location:ftp://download:1bk3l4s3k9s2@232.2.2 ......
<?php
class useful{
/*
* ³£Óú¯ÊýÀà
* ×÷ Õߣº¶à²ËÄñ
* ÁªÏµÓÊÏ䣺kingerq AT msn DOT com
* ´´½¨Ê±¼ä£º2005-07-18
* À´Ô´£ºhttp://blog.csdn.net/kingerq
*/
/*
* ¹¦ÄÜ£º¸ñʽ»¯Êý×Ö£¬ÒÔ±ê×¼MONEY¸ñʽÊä³ö
*/
function formatnumber($num){
return number_format($num, 2, ".", ",");
}
/*
* ¹¦ÄÜ£º¸ñʽ»¯Îı¾£¬½«\nת³É<br>µÈ
* ²ÎÊý£º$string À´Ô´×Ö·û´®
* ·µ»Ø£º´¦ÀíºóµÄ×Ö·û´®
*/
function formatstring($string = ""){
$string = preg_replace(array("/\s+/", "/\'/"), array(" ", "\"\""), $string);
$string = htmlspecialchars($string);
return nl2br($string);
}
/*
* ¹¦ÄÜ£º¸ñʽ»¯Îı¾Êä³ö
* ²ÎÊý $text ΪÐè¸ñʽ»¯µÄÎı¾ÄÚÈÝ
* É÷Óã¬Èç¹ûÈÃÓû§ÊäÈëµÄ¿ÉÖ´ÐдúÂëÔÚformatstring´¦Àíºó²åÈçÊý¾Ý¿â£¬È»ºóʹÓô˺¯Êý»áÈôúÂëÖ´ÐÐ
*/
fun ......
ÔÀí
Ò»°ã£¬ÓÐ2ÖÖ·½·¨¿ÉÒÔµ¼³ödocÎĵµ£¬Ò»ÖÖÊÇʹÓÃcom£¬²¢ÇÒ×÷ΪphpµÄÒ»¸öÀ©Õ¹¿â°²×°µ½·þÎñÆ÷ÉÏ£¬È»ºó´´½¨Ò»¸öcom£¬µ÷ÓÃËüµÄ·½·¨¡£°²×°¹ýofficeµÄ·þÎñÆ÷¿ÉÒÔµ÷ÓÃÒ»¸ö½Ðword.applicationµÄcom£¬¿ÉÒÔÉú³ÉwordÎĵµ£¬²»¹ýÕâÖÖ·½Ê½ÎÒ²»ÍƼö£¬ÒòΪִÐÐЧÂʱȽϵͣ¨ÎÒ²âÊÔÁËһϣ¬ÔÚÖ´ÐдúÂëµÄʱºò£¬·þÎñÆ÷»áÕæµÄÈ¥´ò¿ªÒ»¸öword¿Í»§¶Ë£©¡£ÀíÏëµÄcomÓ¦¸ÃÊÇûÓнçÃæµÄ£¬ÔÚºǫ́½øÐÐÊý¾Ýת»»£¬ÕâÑùЧ¹û»á±È½ÏºÃ£¬µ«ÊÇÕâЩÀ©Õ¹Ò»°ãÐèÒªÊÕ·Ñ¡£
µÚ2ÖÖ·½·¨£¬¾ÍÊÇÓÃPHP½«ÎÒÃǵÄdocÎĵµÄÚÈÝÖ±½ÓдÈëÒ»¸öºó׺ΪdocµÄÎļþÖм´¿É¡£Ê¹ÓÃÕâÖÖ·½·¨²»ÐèÒªÒÀÀµµÚÈý·½À©Õ¹£¬¶øÇÒÖ´ÐÐЧÂʽϸߡ£
word±¾ÉíµÄ¹¦ÄÜ»¹ÊǺÜÇ¿´óµÄ£¬Ëü¿ÉÒÔ´ò¿ªhtml¸ñʽµÄÎļþ£¬²¢ÇÒÄܹ»±£Áô¸ñʽ£¬¼´Ê¹ºó׺Ϊdoc£¬ËüÒ²ÄÜʶ±ðÕý³£´ò¿ª¡£Õâ¾ÍΪÎÒÃÇÌṩÁË·½±ã¡£µ«ÊÇÓÐÒ»¸öÎÊÌ⣬html¸ñʽµÄÎļþÖеÄͼƬֻÓÐÒ»¸öµØÖ·£¬ÕæÕýµÄͼƬÊDZ£´æÔÚÆäËûµØ·½µÄ£¬Ò²¾ÍÊÇ˵£¬Èç¹û½«HTML¸ñʽдÈëdocÖУ¬ÄÇôdocÖн«²»Äܰüº¬Í¼Æ¬¡£ÄÇÎÒÃÇÈçºÎ´´½¨°üº¬Í¼Æ¬µÄdocÎĵµÄØ£¿ÎÒÃÇ¿ÉÒÔʹÓúÍhtmlºÜ½Ó½üµÄmht¸ñʽ¡£
mht¸ñʽºÍhtmlºÜÀàËÆ£¬Ö»²»¹ýÔÚmht¸ñʽÖУ¬ÍⲿÁ´½Ó½øÀ´ ......
Ê×ÏÈÕâ2¸öº¯Êý¶¼ÊǾßÓÐÌæ»»×Ö·û¹¦Äܵġ£µ«ÊÇstrtr±Èstr_replaceÐÔÄÜÉÏÒª¿é4±¶¡£¾ßÌåÇé¿öÇë¿´ÈçÏ·ֽ⣺
Ê×ÏÈÊÇstrtrº¯Êý£º
ʵÀý1£ºµ±
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
<?php
//Õâ¸öʱºòÊä³öµÄΪbaicai¶ø²»ÊÇbai123cai,ÒòΪstr("pao")<strlen("bai123")
echo strtr("paocai!","pao","bai123");
?>
ʵÀý2£ºµ±±»Ìæ»»µÄÖµ³¤¶ÈСÓÚ±»Ì滻Ŀ±êµÄʱºò
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
<?php
//Õâ¸öʱºòÊä³öµÄΪlaocai¶ø²»ÊÇlacai,ÒòΪstr("pao")>strlen("la")
echo strtr("paocai!","pao","la");
?>
ʵÀý3£ºÖ§³ÖÊý×éÌæ»»
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
<?php
$Arr=array('ao'=>'oa','ai'=>'ia');
echo strtr("paocai!",$Arr); //Õâ¸öʱºòÊä³öµÄΪpoacia
?>
Æä´ÎÊÇstr_replace£º
ÒÔÏÂΪÒýÓõÄÄÚÈÝ£º
<?php
echo str_replace("you","paocai","I love you!"); //»áÊä³öI love paocai!
?>
×ܽ᣺strtrËûÊǸú×Ö·û³¤¶ÈÓйØÏµµÄ£¬µ«ÊÇstr_replace¾ÍûÓйØÏµ£¬¹À¼ÆÔÚÔËÐв½ÖèµÄʱºò»á¶ÁÈ¡×Ö·û´®³¤¶ÈËùÒԲŻá±ÈstrtrÂýºÜ¶à¡£ ......
pack/unpackµÄÃþ°å×Ö·û×Ö·ûº¬Òå
format ²ÎÊýµÄ¿ÉÄÜÖµ£º
a - NUL-padded string
A - SPACE-padded string
h - Hex string, low nibble first
H - Hex string, high nibble first
c - signed char
C - unsigned char
s - signed short (always 16 bit, machine byte order)
S - unsigned short (always 16 bit, machine byte order)
n - unsigned short (always 16 bit, big endian byte order)
v - unsigned short (always 16 bit, little endian byte order)
i - signed integer (machine dependent size and byte order)
I - unsigned integer (machine dependent size and byte order)
l - signed long (always 32 bit, machine byte order)
L - unsigned long (always 32 bit, machine byte order)
N - unsigned long (always 32 bit, big endian byte order)
V - unsigned long (always 32 bit, little endian byte order)
f - float (machine dependent size and representation)
d - double (machine dependent size and representation)
x - NUL byte
X - Back up one byte
@ - NUL-fill to absolute position
aÒ»¸öÌî³ä¿ ......