ฟังก์ชั่น ง่ายๆ ที่หลายคนยังไม่รู้ วันนี้มีทั้งหมด 9 ฟังก์ชั่น

 

::javascript::
1-------go to top window--------
window.scrollTo(0,0);

2------Close Window with prompt-----
window.top.window.top.window.top.window.opener = self; window.top.window.top.window.top.window.top.close();

3--------- Fomate date for MySql ----------
function formatDate(date1) 
{
  return date1.getFullYear() + '-' +
    (date1.getMonth() < 9 ? '0' : '') + (date1.getMonth()+1) + '-' +
    (date1.getDate() < 10 ? '0' : '') + date1.getDate();
}

var myDate = new Date();
var nowDate = formatDate(myDate);
alert(nowDate);

4----------option window.open-------------
channelmode=yes|no|1|0 
directories=yes|no|1|0 
fullscreen=yes|no|1|0 
height=pixels 
left=pixels 
location=yes|no|1|0 
menubar=yes|no|1|0 
resizable=yes|no|1|0 
scrollbars=yes|no|1|0 
status=yes|no|1|0 
titlebar=yes|no|1|0 
toolbar=yes|no|1|0 
top=pixels 
width=pixels 


::PHP::
1--------insert zero before number----
sprintf("%05d", $i);
ตัวอย่าง ถ้า $i = 5 ผลลัพธ์คือ 00005

2-------get servername------
function getServerName()
{
 $protocol = 'http';
 if (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443') 
  $protocol = 'https';
 $host = $_SERVER['HTTP_HOST'];
 $baseUrl = $protocol . '://' . $host;
 if (substr($baseUrl, -1)=='/')
  $baseUrl = substr($baseUrl, 0, strlen($baseUrl)-1);

 return $baseUrl;
}


3------------charset 'utf-8' header---------
header('Content-type: text/html; charset=utf-8');

4------------php+ javascript alert----------
echo '<script type="text/javascript">';
    echo 'alert("Your text here");';
echo '</script>
';


5------------different day-------------
$date0 = "2007-08-07";     
$date1 = "2007-07-31";     
$dif = (( strtotime($date0) - strtotime($date1) ) / ( 60 * 60 * 24 ));
echo $date0.'ถึง'.$date1.' ห่างกัน'. $dif .'วัน'; 


6----------change action event onclick---------
onclick="document.myform.action='actPage.php'
actPage.php => หน้าที่เราต้องการทำหลังจากกด submit

เมื่อก่อนที่ผมไม่รู้จัก even ตัวนี้ ผมก็ใช้ if เอาครับโดยถ้าต้องการทำ action ไหนก็ต้องมีการ submit ก่อน จึงจะเช็ค แต่อันนี้เช็คก่อนที่เราจะ submit ไม่ต้อง if ให้วุ่นวาย


7---------function ส่ง e-mail Encoding UTF-8------
function sendmail($from, $to, $subject, $message)
 {
  if($message)
  {
   $subject = "=?utf-8?B?".base64_encode($subject)."?="; //  หัวข้ออีเมล์
   $headers = "MIME-Version: 1.0\r\n"; 
   $headers .= "Content-Type: text/html; charset=utf-8 \r\n"; // encoding
   $headers .= "From: ".$from." \r\n"; 
   
   return mail($to, $subject, $message, $headers);
  }  
 }


ตัวอย่างการเรียกใช้
sendmail($from, $to, $subject, $message);
8------------------display error------------------
ini_set("display_errors", "1");
ini_set("error_reporting", "E_ALL");

ถ้าใครใช้ไม่ได้ก็มาโพสถามได้นะครับ
และถ้าต้องการ ทราบฟังก์ชันอะไรก็โพสถามในนี้ได้นะครับ

 

 

^