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

2014年6月14日 星期六

勿再使用舊php 例如$HTTP_GET_VARS

勿再使用舊php 例如$HTTP_GET_VARS
改成$_GET
改成$_SESSION

不然很多會出錯

2011年12月22日 星期四

function裡藥用外部變數要在裡面加global

$count_title=0;
function for_count_use(){
global $count_title;//要用外部變數要這樣用
$count_title++;
echo $count_title;
}

php 絕對位置

//php用得絕對位置
$root_Path=$_SERVER['DOCUMENT_ROOT'].'/Houli/';
//HTML用的連結時的絕對路徑
$root_Path_html="http://localhost/Houli/";

//include時要用$root_Path(D:wamp/www/xxxx) ,src的HTML用法要$root_Path_html

2011年12月20日 星期二

2011年11月25日 星期五

array用法

$mealsArray=array();
$i=0;
do {
$mealsArray[i]=array();
$mealsArray[i]=$row_RecNews;
}while()

2011年6月21日 星期二

上傳檔案檔名中文一樣可上傳 for Windows

$Chinese_file_name=mb_convert_encoding($_FILES[datafile][name][$j],"big5","utf8");
copy($_FILES[datafile][tmp_name][$j],'upload'.$Chinese_file_name);//複製暫存檔案到指定資料夾

2011年6月20日 星期一

前往上一筆、下一筆資料

概念 創一個撈全部的資料集 在跟指定資料集比對id 如果比對到了 就從比對到的筆數 進行上一筆 下一筆

//RecNews 指定資料集
$colname_RecNews = "-1";
if (isset($_GET['news_id'])) {
  $colname_RecNews = $_GET['news_id'];
}
mysql_select_db($database_connectPrince, $connectPrince);
$query_RecNews = sprintf("SELECT * FROM news WHERE news_id = %s  AND news_active=1 ", GetSQLValueString($colname_RecNews, "int"));
$RecNews = mysql_query($query_RecNews, $connectPrince) or die(mysql_error());
$row_RecNews = mysql_fetch_assoc($RecNews);
$totalRows_RecNews = mysql_num_rows($RecNews);

//RecNewsAll 全部資料集 要把$row_RecNewsAll = mysql_fetch_assoc($RecNewsAll);;給註解掉才不會衝突
mysql_select_db($database_connectPrince, $connectPrince);
$query_RecNewsAll = "SELECT * FROM news WHERE news_active = 1 ORDER BY news_date DESC";
$RecNewsAll = mysql_query($query_RecNewsAll, $connectPrince) or die(mysql_error());
//$row_RecNewsAll = mysql_fetch_assoc($RecNewsAll);
$totalRows_RecNewsAll = mysql_num_rows($RecNewsAll);

//=======================================================
$id=$_GET['news_id'];
$ii = 0;
while($row = mysql_fetch_array($RecNewsAll)){
if($row["news_id"] == $id){
break;
}
$ii++;
}

//上一筆
if($ii > 0){
mysql_data_seek($RecNewsAll, $ii-1);
$row1 = mysql_fetch_array($RecNewsAll);

}
//下一筆
if($ii < mysql_num_rows($RecNewsAll)-1){
mysql_data_seek($RecNewsAll, $ii+1);
$row2 = mysql_fetch_array($RecNewsAll);
}

//=======================================================

2011年5月31日 星期二

2010年11月13日 星期六

如果怎樣都這樣 Cannot modify header information - headers already sent by

可能是空白造成的
如果怎樣都無法解決
試著開一個新檔案Untitled-1.php
然後把原本的程是馬複製到這一頁來 存檔!!解決!!
good job

2010年4月10日 星期六

GD2簡單裁圖寫法

$big_width=550;
$big_height=500;
$small_width=143;
$small_height=104;

$destDir = "upload_image/news";

//檔案命名
$Name = date("YmdHis") . "_" . substr(md5(uniqid(rand())),0,5) . "." . $Ext;
//複製暫存檔
copy($_FILES['Photo3']['tmp_name'][$i] , $destDir . "/" . $Name );

//預覽圖
$src = $destDir . "/" . $Name;
$dest = $destDir . "/thum/" . "thum_" . $Name;
$destW = $small_width;
$destH = $small_height;
$nb3=$Name;//存圖片名稱
imagesResizeSmall($src,$dest,$destW,$destH);

function imagesResizeSmall($src,$dest,$destW,$destH) {
if (file_exists($src) && isset($dest)) {
//取得檔案資訊
$srcSize = getimagesize($src);
$srcExtension = $srcSize[2];
$srcRatio = $srcSize[0] / $srcSize[1];
//依長寬比判斷長寬像素
$destH = $destW / $srcRatio;
}

//建立影像 建立小圖的框
if($destH>=104){
$destImage = imagecreatetruecolor($destW, 104);
}else{
$destImage = imagecreatetruecolor($destW, $destH);
}
//根據檔案格式讀取圖檔
switch ($srcExtension) {
case 1: $srcImage = imagecreatefromgif($src); break;
case 2: $srcImage = imagecreatefromjpeg($src); break;
case 3: $srcImage = imagecreatefrompng($src); break;
}

//取樣縮圖 取大圖縮放後 放在小圖的框裡
imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0,$destW,$destH,imagesx($srcImage), imagesy($srcImage));

//輸出圖檔
switch ($srcExtension) {
case 1: imagegif($destImage,$dest); break;
case 2: imagejpeg($destImage,$dest,100); break;
case 3: imagepng($destImage,$dest); break;

//釋放資源
imagedestroy($destImage);
}
}

2010年3月22日 星期一

Rewrite網址

常常看到 xxx1547.html但明明是php的網站
那就是利用Rewrite網址辦到的

1.
是用wamp的話 選擇Apache Modules的rewrite_module把他開啟
2.在根目錄資料夾放一個檔名叫做.htaccess檔案
在裡面寫規則 把什麼換成什麼
例如要把noticedetail33.html換成
noticedetail.php?not_id=33
(但實際看到是noticedetail33.html)
也就是雖然使用者輸入的是noticedetail33.html
看到的也是noticedetail33.html但其實內部給網址實是給成noticedetail.php?not_id=33
就這樣寫
RewriteRule ^noticedetail(\w+).html?$ noticedetail.php?not_id=$1
//全部是
RewriteEngine on
#RewriteBase /
#3
RewriteRule ^noticedetail(\w+).html?$ noticedetail.php?not_id=$1

(底下這步還在困擾)
但是原本你寫的檔案noticedetail.php裡的程式原本是寫成noticedetail.php?not_id=<?php echo $GET['not_id'];?>的話都要改寫成noticedetail<?php echo $GET['not_id'];?>.html

2010年3月11日 星期四

PHP導向目前網址兼帶目前參數

$filename_logout = basename($_SERVER['PHP_SELF']);//轉到目前網址不帶參數
$filename = $_SERVER['REQUEST_URI'];//帶著參數轉到目前網址

$_SERVER[PHP_SELF]=’/index.php’
$_SERVER[SCRIPT_NAME]=’/index.php’
$_SERVER[QUERY_STRING]=’u=admin&p=123456′
$_SERVER[REQUEST_URI]=’/index.php?u=admin&p=123456′

從上面2個例子來看,大概也可以歸類幾個重點:
$_SERVER[QUERY_STRING]:查詢的字串,也就是獲取?後面的查詢字串
$_SERVER[REQUEST_URI]:取得網域名稱後面所有的字串,也就是http://homeserver.com.tw後面所有的字串

寄信標題亂碼(outlook收信之類的)

//寄信
$mailtype='Content-Type:text/html;charset=utf8';
$mailFrom=$_POST['cn_email'];
$mailTo=xxx@xxx.com.tw';
$mailCC='link7311@gmail.com';
$mailBCC='';
$mailSubject=$_POST['cn_title'];
$mailSubject = "=?UTF-8?B?" . base64_encode($mailSubject) . "?=";//<---------要加這一行
$mailContent = "Content: ";
$mailContent .=nl2br($_POST['cn_content']);
$mailContent .= "<br>";
$mailContent .= "Name: ";
$mailContent .= $_POST['cn_name'];
$mailContent .= "<br>";
$mailContent .= "Phone: ";
$mailContent .= $_POST['cn_phone'];
$mailContent .= "<br>";
$mailContent .= "Company: ";
$mailContent .= $_POST['cn_company'];
$mailContent .= "<br>";
$mailContent .= "Email: ";
$mailContent .= $_POST['cn_email'];
$mailContent .= "<br>";
$maildata = "From:$mailFrom\r\n";
if ($mailCC != '') {
$maildata .= "CC:$mailCC\r\n";
}
if ($mailBCC != '') {
$maildata .= "BCC:$mailBCC\r\n";
}
$maildata .= "$mailtype";
mail($mailTo,$mailSubject,$mailContent,$maildata);

2010年2月26日 星期五

imageMagic先等比縮圖再裁切

//切記後面都要有空格"convert -resize 143 空格"."imageMagic/01.jpg"." 空格"."imageMagic/01_conver.jpg"

//先縮圖
$exec_str="convert -resize 143 "."imageMagic/02.jpg"." "."imageMagic/02_conver.jpg";//以寬為比例
exec($exec_str);

//再裁切
$exec_str="convert -crop 143x104+0+0 "."imageMagic/02_conver.jpg"." "."imageMagic/02_crop.jpg";//裁切圖+0+0是指偏移量
exec($exec_str);

2010年2月25日 星期四

資料集導覽列勿忘這一行

$currentPage = $_SERVER["PHP_SELF"];//<--這行一定要呀

搜尋並取代字串(關鍵字變紅色)

<?php
function searchReplace($content,$keyword){
$change = ereg_replace ( $keyword, '<strong><span class="search13">'.$keyword.'</span><strong>', $content);
return $change;
}
?>

CSS

.search13 {
text-transform: none;
color: #FF0000;
font-size: 13px;
letter-spacing: 0.1em;
text-indent: 1px;
word-spacing: 0.6em;
}

用法
1.先配合MySql搜尋(看自己的記憶碎片第六片-php關鍵字搜尋)
2.searchReplace($row_RecNews['news_content'] ,$_GET['keyword']);
3.那個keyword是從上一頁GET過來的
4.可配合切割中文字元

2010年2月7日 星期日

切割中文字元

mb_substr(strip_tags($row_RecNews['news_content']),0,68,"UTF-8");

用mb_substr 這樣可以正確切割中文字元 但還是會有英文問題 先用用吧

2010年1月11日 星期一

記憶碎片第六片-php 關鍵字搜尋

搜尋
$query_RecNews = sprintf("SELECT * FROM news WHERE news_subject LIKE %s AND news_active = 1 ORDER BY news_date DESC", GetSQLValueString("%" . $colname_RecNews . "%", "text"));

LIKE %s 然後 用GetSQLValueString("%" . $colname_RecNews . "%", "text"));//兩個%符號夾中間

可模糊搜尋到只要有 包含關鍵字就出來