日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP笔记随笔

發布時間:2023/11/29 php 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP笔记随笔 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.CSS控制頁面文字不能復制:

body{-webkit-user-select:none;}

?

2.【php過濾漢字和非漢字】

$sc="aaad....##--__i漢字過濾"; //iconv("UTF-8","GB2312",$sc);utf-8轉碼

echo $temp=eregi_replace("[^\x80-\xff]","",$sc); //保留漢字(過濾非漢字)

echo $temp=preg_replace("/[\\x80-\\xff]/","",$sc); //保留非漢字(過濾漢字),注意兩條反斜線

?

3.查詢數據庫中某個字段中用逗號分隔的字符串是否包含用戶傳遞的某個值,這樣寫SQL語句:

SELECT * FROM tb WHERE field LIKE '%,1' OR field LIKE '1,%' OR field LIKE '%,1,%' OR field = '1'

查詢結果見圖。不知道是否有更簡單的方法,目前這樣可行。感謝學敏!

?

?

4.PHP上傳文件獲取后綴名:

$temp_arr = explode(".", $upload_file_name);

$file_ext = array_pop($temp_arr);

$file_ext = trim($file_ext);

$file_ext = strtolower($file_ext); //$file_ext 文件的后綴

?

5.PHP獲取圖片尺寸大小

$arr=getimagesize("1.jpg");

echo $arr[0]."< br/ >"; //the width

echo $arr[1]; //the height

?

6.PHP:Deprecated: Function set_magic_quotes_runtime() is deprecated解決方案:

php.ini 修改:error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED

?

7.echo $thisUrl=dirname('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']).'/../../';exit;

?

8.PHP 匹配多對中括號中的內容,如下:

$string = "這是[3]def[25]我的[26]想說的話[wer3][as][41]正則匹配!";

preg_match_all('/\[([a-z0-9]+)\]/', $string, $matches);

print_r($matches);

?

9.$qqContent='(頁面內容)';

$pat = '/<div class="allnum">.+?<\/div>/';

$str=str_replace("\r", "",$qqContent);

$str=str_replace("\n", "",$str);

preg_match_all($pat, $str, $res);

提取數字用:

preg_match_all('/\d+/', $res[0][0], $nums);

print_r($nums[0][0]); //得到結果。

?

10.PHP獲取當前頁面的所有超鏈接:

$str = '(包含超鏈接的字符串)';

$pat = '/<a(.*?)href="(.*?)"(.*?)>(.*?)<\/a>/i';

preg_match_all($pat, $str, $m);

print_r($m); ?//其中$m[2]為超鏈接內容,$m[4]為超鏈接的標題。

?

11.Linux 解壓

解壓tar.bz2方法:tar -vxjf filename.tar.bz2

解壓tar.gz 方法: tar zxvf filename.tar.gz

解壓zip方法:unzip filename.zip

?

12.Linux 壓縮當前目錄下的文件夾

tar -zcvf common.tar.gz common,此命令:壓縮當前目錄下的common文件夾

?

13.匹配圖片路徑:(如果源代碼中有空格,先去掉“\r”和"\n",然后再匹配。)

$str=str_replace("\r", "",$content);

$str=str_replace("\n", "",$str);

$pattern="/<[img|IMG].*?src=[\'|\"](.*?(?:[\.gif|\.jpg]))[\'|\"].*?[\/]?>/";

preg_match_all($pattern,$str,$match);

print_r($match);

?

14.PHP中在遠程路徑(FTP)進行操作,比如創建文件夾:

$remote="ftp://username:password@www.baidu.com/test/txt";mkdir($remote, 0777, true );

意思即為:在baidu網站根目錄創建目錄 /test/txt...,其中username和password分別為當前網站的FTP登錄賬號和密碼。

?

15.判斷一個網絡文件是否存在(兼容所有可能性):

function checkRemoteFileExists($file) {return (bool)fopen($file, 'rb');}

?

16.PHP判斷一個遠程文件是否存在:

$url = "http://url.cn/ERUKm9 ";

$fileExists = @file_get_contents($url, null, null, -1, 1) ? true : false;

echo $fileExists; //返回1,就說明文件存在。

?

17.PHP匹配圖片路徑:

preg_match_all("/<img.*src\s*=\s*[\"|\']?\s*([^>\"\'\s]*)/i",str_ireplace("\\","",$content,$arrs));

$arrs[1][0]就是圖片的路徑!

?

18.PHP中讀取https請求協議的網頁內容,有時候file_get_contents()會出錯,比如這樣的:$userinfo ='https://...';可以使用如下方法:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,$userinfo);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1) ;

$string= curl_exec($ch); //file_put_contents('string.txt', $string);

?

19.PHP正則匹配一對中括號內的內容為空:

$ss="sdfghjfsd[url]88888888888888[/url]";

$ss = preg_replace('/\[url\S*\[\/url\]/', '', $ss);

echo $ss;

?

20.MySQL配置日志文件:

在MySQL安裝目錄下my.ini里面找到[mysqld],給里面加入log="E:/mysql_log.txt",然后重啟Apache,重啟MySQL服務即可。

?

21.MySQL獲取日期的一些函數:

mysql獲取上個月的當前時間:select date_sub(now(),interval 1 month) ;

獲取上個月的第一天:select date_sub(date_sub(date_format(now(),'%y-%m-%d 08:00:00'),interval extract( day from now())-1 day),interval 1 month);

?

轉載于:https://www.cnblogs.com/rxbook/p/6008956.html

總結

以上是生活随笔為你收集整理的PHP笔记随笔的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。