{"id":52,"date":"2023-02-26T13:23:31","date_gmt":"2023-02-26T05:23:31","guid":{"rendered":"https:\/\/www.aqrboyblog.top\/?p=52"},"modified":"2023-03-31T17:05:40","modified_gmt":"2023-03-31T09:05:40","slug":"php%e4%b8%ad%e5%b8%b8%e7%94%a8%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.aqrboyblog.top\/?p=52","title":{"rendered":"PHP\u4e2d\u5e38\u7528\u65b9\u6cd5"},"content":{"rendered":"\n<p>PHP \u6c42\u4e24\u4e2a\u65e5\u671f\u76f8\u5dee\u5929\u6570<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function diffBetweenTwoDays ($day1, $day2)\n\n&nbsp; &nbsp; {\n\n&nbsp; &nbsp; &nbsp; &nbsp; $second1 = strtotime($day1);\n\n&nbsp; &nbsp; &nbsp; &nbsp; $second2 = strtotime($day2);\n\n&nbsp; &nbsp; &nbsp; &nbsp; if ($second1 &lt; $second2) {\n\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $tmp = $second2;\n\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $second2 = $second1;\n\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $second1 = $tmp;\n\n&nbsp; &nbsp; &nbsp; &nbsp; }\n\n&nbsp; &nbsp; &nbsp; &nbsp; return ($second1 - $second2) \/ 86400;\n\n&nbsp; &nbsp; }<\/code><\/pre>\n\n\n\n<p>PHP\u4e2d\u8c03\u7528URL<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ch = curl_init();\ncurl_setopt($ch, CURLOPT_URL, \"https:\/\/www.baidu.com\/\");\ncurl_setopt($ch, CURLOPT_HEADER, 0);\ncurl_exec($ch);\ncurl_close($ch);<\/code><\/pre>\n\n\n\n<p>PHP\u6587\u4ef6\u64cd\u4f5c<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>&#8220;r&#8221; \uff08\u53ea\u8bfb\u65b9\u5f0f\u6253\u5f00\uff0c\u5c06\u6587\u4ef6\u6307\u9488\u6307\u5411\u6587\u4ef6\u5934\uff09<\/li>\n\n\n\n<li>&#8220;r+&#8221; \uff08\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00\uff0c\u5c06\u6587\u4ef6\u6307\u9488\u6307\u5411\u6587\u4ef6\u5934\uff09<\/li>\n\n\n\n<li>&#8220;w&#8221; \uff08\u5199\u5165\u65b9\u5f0f\u6253\u5f00\uff0c\u6e05\u9664\u6587\u4ef6\u5185\u5bb9\uff0c\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728\u5219\u5c1d\u8bd5\u521b\u5efa\u4e4b\uff09<\/li>\n\n\n\n<li>&#8220;w+&#8221; \uff08\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00\uff0c\u6e05\u9664\u6587\u4ef6\u5185\u5bb9\uff0c\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728\u5219\u5c1d\u8bd5\u521b\u5efa\u4e4b\uff09<\/li>\n\n\n\n<li>&#8220;a&#8221; \uff08\u5199\u5165\u65b9\u5f0f\u6253\u5f00\uff0c\u5c06\u6587\u4ef6\u6307\u9488\u6307\u5411\u6587\u4ef6\u672b\u5c3e\u8fdb\u884c\u5199\u5165\uff0c\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728\u5219\u5c1d\u8bd5\u521b\u5efa\u4e4b\uff09<\/li>\n\n\n\n<li>&#8220;a+&#8221; \uff08\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00\uff0c\u901a\u8fc7\u5c06\u6587\u4ef6\u6307\u9488\u6307\u5411\u6587\u4ef6\u672b\u5c3e\u8fdb\u884c\u5199\u5165\u6765\u4fdd\u5b58\u6587\u4ef6\u5185\u5bb9\uff09<\/li>\n\n\n\n<li>&#8220;x&#8221; \uff08\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5e76\u4ee5\u5199\u5165\u65b9\u5f0f\u6253\u5f00\uff0c\u5982\u679c\u6587\u4ef6\u5df2\u5b58\u5728\u5219\u8fd4\u56de FALSE \u548c\u4e00\u4e2a\u9519\u8bef\uff09<\/li>\n\n\n\n<li>&#8220;x+&#8221; \uff08\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u5e76\u4ee5\u8bfb\u5199\u65b9\u5f0f\u6253\u5f00\uff0c\u5982\u679c\u6587\u4ef6\u5df2\u5b58\u5728\u5219\u8fd4\u56de FALSE \u548c\u4e00\u4e2a\u9519\u8bef\uff09<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>$file = fopen(\"test.txt\",\"r\");\n$file = fopen(\"\/home\/test\/test.txt\",\"r\");\n$file = fopen(\"\/home\/test\/test.gif\",\"wb\");\n$file = fopen(\"http:\/\/www.example.com\/\",\"r\");\n$file = fopen(\"ftp:\/\/user:password@example.com\/test.txt\",\"w\");\n\n\/\/\u5199\u5165\u6570\u636e\n$content  = \"\";\nfile_put_contents($path,$content, FILE_APPEND );\n\n\/\/\u8bfb\u53d6\u4ece.csv\u6587\u4ef6\n$fp = fopen($path, 'r');\nwhile($line = fgetcsv($fp)){\n echo $line;\n}\nfclose($fp);<\/code><\/pre>\n\n\n\n<p>PHPExcel<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>require_once '\/www\/wwwroot\/tp5\/public\/phpexcel\/PHPExcel.php';\n$user_path = \"\/www\/wwwroot\/tp5\/public\/uploads\/\";\n$objPHPExcel = new \\PHPExcel();\n\/\/ \u8bbe\u7f6esheet\n$objPHPExcel->setActiveSheetIndex(0);\n\/\/ \u8bbe\u7f6e\u5217\u7684\u5bbd\u5ea6\n$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);\n\/\/ \u8bbe\u7f6e\u8868\u5934\n$objPHPExcel->getActiveSheet()->SetCellValue('A1', '\u6635\u79f0');\n\/\/ \u8bbe\u7f6e\u6570\u636e\n$objPHPExcel->getActiveSheet()->SetCellValue('A' . $num, $v&#91;'nickname']);\n\/\/ \u6587\u4ef6\u540d\u79f0\n$fileName = \"\u6587\u4ef6\" . date('Y-m-d', time()) . rand(1, 1000);\n$xlsName = iconv('utf-8', 'gb2312', $fileName);\n\/\/dump($xlsName);die;\n\/\/ \u8bbe\u7f6e\u5de5\u4f5c\u8868\u540d\n$objPHPExcel->getActiveSheet()->setTitle('sheet');\n\/\/\u4e0b\u8f7d excel5\u4e0eexcel2007\n$objWriter = new \\PHPExcel_Writer_Excel2007($objPHPExcel);\n$objWriter->save($user_path.$fileName.'.xls');<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p class=\"text-justify\">PHP \u6c42\u4e24\u4e2a\u65e5\u671f\u76f8\u5dee\u5929\u6570 PHP\u4e2d\u8c03\u7528UR [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=52"}],"version-history":[{"count":15,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions"}],"predecessor-version":[{"id":67,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions\/67"}],"wp:attachment":[{"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aqrboyblog.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}