Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > PHP > PHP Forum > รบกวนช่วยอธิบายโค๊ดหน้า function ให้หน่อยค่ะ พอดีไม่เข้าใจโค๊ดค่ะ


[PHP] รบกวนช่วยอธิบายโค๊ดหน้า function ให้หน่อยค่ะ พอดีไม่เข้าใจโค๊ดค่ะ

 
Topic : 075963



โพสกระทู้ ( 16 )
บทความ ( 0 )



สถานะออฟไลน์



Code (PHP)
001.<?php
002.    class MyClass{
003.        public function selQuery($sqlTxt){
004.            if(preg_match('/SELECT/', strtoupper($sqlTxt))){
005.                $result = mysql_query($sqlTxt);
006.                $num = mysql_num_rows($result);
007.                if($num > 0){
008.                    $arrRec = array();
009.                    while($rs = mysql_fetch_assoc($result)){
010.                        array_push($arrRec,$rs);
011.                    }
012.                    return $arrRec;
013.                }else{
014.                    echo null;
015.                }
016.            }else{
017.                echo null;
018.            }
019.        }
020. 
021.        public function query($sql){
022.            if(@mysql_query($sql))
023.                return true;
024.            else
025.                return false;
026.        }
027.         
028.        public function chkUniqData($tablename,$field,$data){
029.            $result = mysql_query("Select $field From $tablename Where $field = '$data'");
030.            $num = mysql_num_rows($result);
031.            if($num >= 1)
032.                return false;
033.            else
034.                return true;
035.        }
036. 
037.        public function random_id($len){
038.            srand((double)microtime()*10000000);
039.            $chars = "0123456789";
040.            $ret_str = "";
041.            $count = 0;
042.            $chars2 = "";
043.            while($count<strlen($chars)){
044.                for($i=0;$i<$len;$i++){
045.                    $chars2 .= $chars[$count];
046.                }
047.                $count++;
048.            }
049.            $num = strlen($chars2);
050.            for($i = 0; $i < $len; $i++)
051.                {
052.                    $ret_str.= $chars2[rand()%$num];
053.                    $ret_str.="";
054.                }
055.            return $ret_str;
056.        }
057. 
058.        public function getDateFormat($timestamp, $type = "d"){
059.            $d = date("d", $timestamp);
060.            $m = date("m", $timestamp);
061.            $y = date("Y", $timestamp)+543;
062.            $h = date("H", $timestamp);
063.            $i = date("i", $timestamp);
064.            $s = date("s", $timestamp);
065.            $thai_m = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม",
066.                "กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
067.            if($type == "d"){
068.                return $d." ".$thai_m[$m-1]." ".$y;
069.            }else if($type == "dt"){
070.                return $d." ".$thai_m[$m-1]." ".$y.", เวลา ".$h.":".$i."น.";
071.            }
072.        }
073. 
074.        public function uploadPhoto($arrFile,$name,$dirnm,$limit=0,$option='w'){
075.            $array_last=explode(".", $arrFile['name']);
076.            $c=count($array_last)-1;
077.            $filename=strtolower($array_last[$c]);
078.            $photo_name = $name.'.'.$filename;
079.            $chk=false;
080.            $arrAuthorList=array('jpg','jpeg','gif','png');
081.            foreach($arrAuthorList as $key){
082.                if($key==$filename){
083.                    $chk=true;
084.                    break;
085.                }
086.            }
087.            if($chk){
088.                copy($arrFile['tmp_name'], $dirnm.$photo_name);
089.                $images = $dirnm.$photo_name;
090.                $img_size=GetimageSize($images);
091.                if($option=='w' AND $limit>0){
092.                    if($img_size[0]>$limit){
093.                        $img_width=$limit;
094.                        $img_height=round($img_width*$img_size[1]/$img_size[0]);
095.                    }else{
096.                        $img_width=$img_size[0];
097.                        $img_height=$img_size[1];
098.                    }
099.                }else if($option=='h' AND $limit>0){
100.                    if($img_size[1]>$limit){
101.                        $img_height=$limit;
102.                        $img_width=round($img_height*$img_size[0]/$img_size[1]);
103.                    }else{
104.                        $img_width=$img_size[0];
105.                        $img_height=$img_size[1];
106.                    }
107.                }else{
108.                    $img_width=$img_size[0];
109.                    $img_height=$img_size[1];
110.                }
111. 
112.                if($filename=="jpg" or $filename=="jpeg"){
113.                    $newImg=ImageCreateFromJPEG($images);
114.                    $newX=ImagesX($newImg);
115.                    $newY=ImagesY($newImg);
116.                    $images_fin=ImageCreateTrueColor($img_width, $img_height);
117.                    ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY);
118.                    ImageJPEG($images_fin, $dirnm.$photo_name);
119.                }else if($filename=="gif"){
120.                    $newImg=ImageCreateFromGIF($images);
121.                    $newX=ImagesX($newImg);
122.                    $newY=ImagesY($newImg);
123.                    $images_fin=ImageCreateTrueColor($img_width, $img_height);
124.                    ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY);
125.                    ImageGIF($images_fin, $dirnm.$photo_name);
126.                }else if($filename=="png"){
127.                    $newImg=ImageCreateFromPNG($images);
128.                    $newX=ImagesX($newImg);
129.                    $newY=ImagesY($newImg);
130.                    $images_fin=ImageCreateTrueColor($img_width, $img_height);
131.                    ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY);
132.                    ImagePNG($images_fin, $dirnm.$photo_name);
133.                }
134. 
135.                ImageDestroy($newImg);
136.                ImageDestroy($images_fin);
137. 
138.                unlink($arrFile['tmp_name']);
139.                return $photo_name;
140.            }else{
141.                return null;
142.            }
143.        }
144. 
145.        public function randomNum($num){
146.            srand((double)microtime()*10000000);
147.            $n = rand()%$num;
148.            return $n;
149.        }
150. 
151.        public function randNonUniqe($num){
152.            srand((double)microtime()*10000000);
153.            $a = array();
154.            while (count($a) < $num) {
155.              $n = rand()%$num;
156.              if (!in_array($n, $a)) array_push($a,$n);
157.            }
158.            return $a;
159.        }
160. 
161.        public function getItemsFromCart($cart){
162.            if (isset($cart)) {
163.                $items = explode(',',$cart); //ใช้คอมม่าเป็นตัวแยกข้อมูล
164.                $contents = array();
165.                foreach ($items as $item) {   
166.                    $contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;   //นำค่าที่ได้มาเก็บในaray
167.                }
168.                return $contents;
169.            }else{
170.                return "";
171.            }
172.        }
173.    }
174.?>




Tag : PHP

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-03-22 16:51:27 By : hikarujun View : 874 Reply : 2
 

 

No. 1



โพสกระทู้ ( 3,848 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Twitter Facebook

จับใส่ tag php หน่อยก็ดีน่ะครับ ดูยากจัง
Code (PHP)
001.?php
002.class MyClass{
003.public function selQuery($sqlTxt){
004.if(preg_match('/SELECT/', strtoupper($sqlTxt))){
005.$result = mysql_query($sqlTxt);
006.$num = mysql_num_rows($result);
007.if($num > 0){
008.$arrRec = array();
009.while($rs = mysql_fetch_assoc($result)){
010.array_push($arrRec,$rs);
011.}
012.return $arrRec;
013.}else{
014.echo null;
015.}
016.}else{
017.echo null;
018.}
019.}
020. 
021.public function query($sql){
022.if(@mysql_query($sql))
023.return true;
024.else
025.return false;
026.}
027. 
028.public function chkUniqData($tablename,$field,$data){
029.$result = mysql_query("Select $field From $tablename Where $field = '$data'");
030.$num = mysql_num_rows($result);
031.if($num >= 1)
032.return false;
033.else
034.return true;
035.}
036. 
037.public function random_id($len){
038.srand((double)microtime()*10000000);
039.$chars = "0123456789";
040.$ret_str = "";
041.$count = 0;
042.$chars2 = "";
043.while($count<strlen($chars)){
044.for($i=0;$i<$len;$i++){
045.$chars2 .= $chars[$count];
046.}
047.$count++;
048.}
049.$num = strlen($chars2);
050.for($i = 0; $i < $len; $i++)
051.{
052.$ret_str.= $chars2[rand()%$num];
053.$ret_str.="";
054.}
055.return $ret_str;
056.}
057. 
058.public function getDateFormat($timestamp, $type = "d"){
059.$d = date("d", $timestamp);
060.$m = date("m", $timestamp);
061.$y = date("Y", $timestamp)+543;
062.$h = date("H", $timestamp);
063.$i = date("i", $timestamp);
064.$s = date("s", $timestamp);
065.$thai_m = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม",
066."กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
067.if($type == "d"){
068.return $d." ".$thai_m[$m-1]." ".$y;
069.}else if($type == "dt"){
070.return $d." ".$thai_m[$m-1]." ".$y.", เวลา ".$h.":".$i."น.";
071.}
072.}
073. 
074.public function uploadPhoto($arrFile,$name,$dirnm,$limit=0,$option='w'){
075.$array_last=explode(".", $arrFile['name']);
076.$c=count($array_last)-1;
077.$filename=strtolower($array_last[$c]);
078.$photo_name = $name.'.'.$filename;
079.$chk=false;
080.$arrAuthorList=array('jpg','jpeg','gif','png');
081.foreach($arrAuthorList as $key){
082.if($key==$filename){
083.$chk=true;
084.break;
085.}
086.}
087.if($chk){
088.copy($arrFile['tmp_name'], $dirnm.$photo_name);
089.$images = $dirnm.$photo_name;
090.$img_size=GetimageSize($images);
091.if($option=='w' AND $limit>0){
092.if($img_size[0]>$limit){
093.$img_width=$limit;
094.$img_height=round($img_width*$img_size[1]/$img_size[0]);
095.}else{
096.$img_width=$img_size[0];
097.$img_height=$img_size[1];
098.}
099.}else if($option=='h' AND $limit>0){
100.if($img_size[1]>$limit){
101.$img_height=$limit;
102.$img_width=round($img_height*$img_size[0]/$img_size[1]);
103.}else{
104.$img_width=$img_size[0];
105.$img_height=$img_size[1];
106.}
107.}else{
108.$img_width=$img_size[0];
109.$img_height=$img_size[1];
110.}
111. 
112.if($filename=="jpg" or $filename=="jpeg"){
113.$newImg=ImageCreateFromJPEG($images);
114.$newX=ImagesX($newImg);
115.$newY=ImagesY($newImg);
116.$images_fin=ImageCreateTrueColor($img_width, $img_height);
117.ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY);
118.ImageJPEG($images_fin, $dirnm.$photo_name);
119.}else if($filename=="gif"){
120.$newImg=ImageCreateFromGIF($images);
121.$newX=ImagesX($newImg);
122.$newY=ImagesY($newImg);
123.$images_fin=ImageCreateTrueColor($img_width, $img_height);
124.ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY);
125.ImageGIF($images_fin, $dirnm.$photo_name);
126.}else if($filename=="png"){
127.$newImg=ImageCreateFromPNG($images);
128.$newX=ImagesX($newImg);
129.$newY=ImagesY($newImg);
130.$images_fin=ImageCreateTrueColor($img_width, $img_height);
131.ImageCopyResampled($images_fin, $newImg, 0, 0, 0, 0, $img_width+1, $img_height+1, $newX, $newY);
132.ImagePNG($images_fin, $dirnm.$photo_name);
133.}
134. 
135.ImageDestroy($newImg);
136.ImageDestroy($images_fin);
137. 
138.unlink($arrFile['tmp_name']);
139.return $photo_name;
140.}else{
141.return null;
142.}
143.}
144. 
145.public function randomNum($num){
146.srand((double)microtime()*10000000);
147.$n = rand()%$num;
148.return $n;
149.}
150. 
151.public function randNonUniqe($num){
152.srand((double)microtime()*10000000);
153.$a = array();
154.while (count($a) < $num) {
155.$n = rand()%$num;
156.if (!in_array($n, $a)) array_push($a,$n);
157.}
158.return $a;
159.}
160. 
161.public function getItemsFromCart($cart){
162.if (isset($cart)) {
163.$items = explode(',',$cart); //ใช้คอมม่าเป็นตัวแยกข้อมูล
164.$contents = array();
165.foreach ($items as $item) {
166.$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1; //นำค่าที่ได้มาเก็บในaray
167.}
168.return $contents;
169.}else{
170.return "";
171.}
172.}
173.}
174.?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-22 16:54:30 By : mangkunzo
 

 

No. 2



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

ยาวขนาดนี้จะให้อธิบายหมดเหรอครับ เอาเป็นว่าถามจุด ๆ แล้วกันครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-03-22 20:43:01 By : webmaster
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : รบกวนช่วยอธิบายโค๊ดหน้า function ให้หน่อยค่ะ พอดีไม่เข้าใจโค๊ดค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่