myAdBanner

顯示具有 PHP 標籤的文章。 顯示所有文章
顯示具有 PHP 標籤的文章。 顯示所有文章

2022年7月6日 星期三

php 轉換成 html

1. 先建立新的.htaccess檔案放在php檔案的目錄。

2. 建立一個Rewrite Engine (URL重寫工具)。

在檔案第一行寫上

RewriteEngine on 
 
3. 設定所在目錄 / 譬如 /test/
 
RewriteBase /test/
 
4. php 轉換成 html
 
RewriteCond %{THE_REQUEST} (.*)\.php  
RewriteRule ^(.*)\.php $1.html [R=301,L]  

RewriteCond %{THE_REQUEST} (.*)\.html  
RewriteRule ^(.*)\.html $1.php [L] 
 
------------------
完整檔案內容
------------------
RewriteEngine On
RewriteBase /test/

RewriteCond %{THE_REQUEST} (.*)\.php
RewriteRule ^(.*)\.php $1.html [R=301,L]

RewriteCond %{THE_REQUEST} (.*)\.html
RewriteRule ^(.*)\.html $1.php [L]  

2022年6月12日 星期日

windows 系統排程執行PHP程式

 步驟如下:

1. 下載 wget.exe 程式

https://eternallybored.org/misc/wget/

2. 將 wget.exe 複製到 C:\windows 資料夾內

3.  撰寫 bat 檔

autorun.bat 內容如下:

--------------------

C:\xampp\php>c:\windows\wget.exe -q http://localhost/autorunl.php

-------------------

參數說明:

-q 不會輸出執行結果

4.排程執行 autorun.bat


2014年12月9日 星期二

計算陣列個數 count 用法

<?php
$data = array(
    "apples" =>
        array("red", "yellow", "pineapples"),
    "bananas" =>
        array("small", "medium", "big"),
    "vegs" =>
        array("potatoes", "carrots", "onions")
);

$rows = count($data,0);
$cols = (count($data,1)/count($data,0))-1;
print "There are {$rows} rows and {$cols} columns in the table!";
?>
There are 3 rows and 3 columns in the table!

2014年7月14日 星期一

檢查網站是否正常連結

File_Get_Contents("../.htm");
或者
CURL
或者
$FP=FSockOpen("www.php.net",80,$errno,$errstr,30);
IF(!$FP){
    Echo 'Find Error:',$errstr($errno),'
\n'; }Else{ fputs($FP,"GET / HTTP/1.0\r\nHost:www.example.com\r\n\r\n"); Echo 'Output:
',Chr(10); While(!feof($FP)){ Echo fgets($FP,128),'
--------
'; } Fclose($FP); }

2014年4月24日 星期四

匯出EXCLE檔案


<?php
$file="output".date("YmdHis").".xls";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$file;");
//將PHP轉成下載的檔案指定名稱與副檔名.xls

echo ''."\n";
echo ''."\n";
echo '';

echo '';

?>

2014年1月7日 星期二

php使用gmail smtp 寄信

<?php
   include("PHPMailer/class.phpmailer.php"); //匯入PHPMailer類別     
  
   $mail= new PHPMailer();          //建立新物件
   $mail->IsSMTP();                 //設定使用SMTP方式寄信
   $mail->SMTPAuth = true;          //設定SMTP需要驗證
   $mail->SMTPSecure = "ssl";       // Gmail的SMTP主機需要使用SSL連線
   $mail->Host = "smtp.gmail.com";  //Gamil的SMTP主機
   $mail->Port = 465;               //Gamil的SMTP主機的SMTP埠位為465埠。
   $mail->CharSet = "big5";         //設定郵件編碼      
  
   $mail->Username = "*********";  //Gmail帳號
   $mail->Password = "*********";  //Gmail密碼      
  
   $mail->From = "xxx@gmail.com"; //設定寄件者信箱
   $mail->FromName = "xxx";                 //設定寄件者姓名
   $mail->Subject = "PHPMailer 測試信件";    //設定郵件標題
   $mail->Body = "大家好,這是一封測試信件! ";  //設定郵件內容
   $mail->IsHTML(true);                     //設定郵件內容為HTML
   $mail->AltBody = $altbody;               //這個設定主要是預防收件者無法顯示HTML信件時的替代文字
   $mail->WordWrap = 50;                    //設定一行最多為50個字元,即每50個字自動斷行
   $mail->AddReplyTo("info@iii.org.tw", "Info"); //設定回函
   $mail->AddBCC("zzz@iii.org.tw", "zzz"); //使用密件副本
   $mail->AddAttachment("/var/tmp/file.tar.gz"); //新增附件檔案
   $mail->AddAttachment("/tmp/image.jpg", "new.jpg"); //附件也可以更改名稱
   $mail->AddAddress("xxxxx@gmail.com", "xxx"); //設定第一位收件者郵件及名稱
   $mail->AddAddress("xxxxx@gmail.com", "xxx"); //設定第二位收件者郵件及名稱      
  
   if(!$mail->Send()) {
       echo "Mailer Error: " . $mail->ErrorInfo;
   }
   else {
       echo "Message sent!";
   }
?>
*注意事項 php.ini 中設定ssl 要開 否則會錯誤 設定方式 搜尋"php_openssl.dll",然後將前方的";"拿掉,若搜尋不到就自己把"extension=php_openssl.dll"這一句加上去,然後存檔重開web server

2013年10月28日 星期一

數字前面補0 使用sprintf

* %% - 返回百分比符號
* %b - 二進位數字
* %c - 依照 ASCII 值的字元
* %d - 帶符號十進位數字
* %e - 可續計數法(比如 1.5e+3)
* %u - 無符號十進位數字
* %f - 浮點數(local settings aware)
* %F - 浮點數(not local settings aware)
* %o - 八進位數
* %s - 字串
* %x - 十六進位數(小寫字母)
* %X - 十六進位數(大寫字母)

< ?php
$number = 123;
$txt = sprintf("With 2 decimals: %1\$.2f
With no decimals: %1\$u",$number);
echo $txt."<br>";
echo sprintf("%05d", 1); 
?>
輸出: With 2 decimals: 123.00 With no decimals: 123 00001

2013年8月26日 星期一

正則式 取出 { } 裡的文字

<?php
$text='{A}fgfgfhf{bb}gdfdd/***4{CC}fs';   

preg_match_all('|{(.+?)}|is', $text, $match);
print_r($match);  
?>