หาค่าความต่างของวันเวลาด้วย php

วิธีการหาความต่างของวัน เวลา  โดยเอาค่าเวลาที่ 2 ลบด้วยเวลาที่ 1 โดยใช้คำสั่ง $strDateTime1 = “12/8/2016 11:22”; $strDateTime2 = “12/8/2016 13:22”; $Difftime = strtotime($strDateTime2) – strtotime($strDateTime1))/ ( 60 * 60 *24); // 1 Hour = 60*60 ภักดี โตแดงนักวิชาการคอมพิวเตอร์ งานพัฒนาระบบเครือข่ายเทคโนโลยีดิจิทัล

การแปลง DateVale(excel) เป็น Date time ด้วย php

วิธีการแปลงค่า Datetime เป็นค่า Datevale ด้วย PHP เนื่องจาก Excel สามารถเปลี่ยน datetime เป็นค่าตัวเลขได้เลยแต่ php ไม่ได้สามารถทำได้ ทำได้เพียงเปลี่ยนเป็น unixtime ด้วยคำสั่ง strtotime() เท่านั้น วิธีนี้สามารเอา unixtime แปลงเป็นค่า datevalue เหมือนในExcel ให้สามารถแปลงค่าได้เหมือนกับสูตรใน excel ได้ ############## ตัวอย่าง Code $get_datetime=”13/8/2016 11:22″; $datetime=str_replace(“/”,”-“,$get_datetime); $fix_value=25569; echo $fix_value+(strtotime($datetime)/86400); Please use this formula to change from Excel date to Unix date, then you can use “gmdate” to get the

Read More

Error ServerName apache not start on Ubuntu Server

  Error : apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1. Set the ‘ServerName’ directive globally to suppress this message   วิธีแก้ไข โดยการ nano /etc/apache2/apache2.conf เพิ่ม  ServerName localhost และเซฟ /etc/init.d/apache2 restart   อ้างอิง : https://askubuntu.com/questions/256013/apache-error-could-not-reliably-determine-the-servers-fully-qualified-domain-n ภักดี โตแดงนักวิชาการคอมพิวเตอร์ งานพัฒนาระบบเครือข่ายเทคโนโลยีดิจิทัล

แปลง string slug ให้เป็นรูปแบบ URL-friendly

URL-friendly แปลตรงๆ url friendly ก็คือที่อยู่ของเว็บไซต์ที่ดูเป็นมิตร ( กับผู้ใช้ ) เป็นประโยชน์ในการสื่อความหมายและก่อให้เกิดความเข้าใจ ทั้งต่อผู้ใช้งานและบรรดา search engine <?php function slug_url($text) { $text = preg_replace(‘~[^\pL\d]+~u’, ‘-‘, $text); $text = iconv(‘utf-8’, ‘us-ascii//TRANSLIT’, $text); $text = preg_replace(‘~[^-\w]+~’, ”, $text); $text = preg_replace(‘~-+~’, ‘-‘, $text); $text = strtolower($text); $text = trim($text, ” \t\n\r\0\x0B-“); if (empty($text)) { return ‘n-a’; } return $text; } print(slug_url(‘PHP Tutorial’));

Read More

การใช้ real_escape_string function เพื่อป้องกัน SQL Injection ในการรับ INPUT

mysqli_real_escape_string () / mysqli :: real_escape_string ใช้เพื่อตัดอักขระพิเศษในสตริงเพื่อใช้ในคำสั่ง SQL การเขียนในรูปแบบ : Object oriented style string mysqli::escape_string ( string $escapestr ) string mysqli::real_escape_string ( string $escapestr ) การเขียนในรูปแบบ : Procedural style string mysqli_real_escape_string ( mysqli $link , string $escapestr ) —————————————————————————- Parameter ที่มีการนำมาเข้ารหัส เช่น NUL (ASCII 0), \n, \r, \, ‘, “, and Control-Z. ตัวอย่างรูปแบบ : Object

Read More

การใช้งาน Line Notify ร่วมกับ PHP & C#

การสร้าง Token เพื่อใช้ในการส่งข้อมูล เข้าสู่ระบบที่ https://notify-bot.line.me  ด้วย Account Line คลิกที่ My Page และเลือก Generate access token (For developers) ตั้งชื่อ Token และ เลือกกลุ่มที่ต้องการสร้าง Token เมื่อได้ Token แล้ว ให้ทำการ Copy ไว้ เนื่องจากระบบ จะไม่แสดง Token นี้ให้เห็นอีกครั้ง จากนั้นในไลน์ จะเห็น line notify เพิ่มขึ้นมาเป็นเพื่อนใหม่ ให้ทำการ invite เข้า ไลน์กลุ่มที่ต้องการ การเขียนโปรแกรม เพื่อส่งข้อมูลให้กับ Line notification ตัวอย่างการเขียนโปรแกรมภาษา PHP เพื่อส่งข้อความ <?php define(‘LINE_API’,”https://notify-api.line.me/api/notify”); $token = “Un2LudBajEKlJs8I7qbWIMkl3f2WjGH56YuDJ9xxxxx”; // ใส่Token

Read More

Open Remote host MySQL

1. nano /etc/mysql/mysql.conf.d/mysqld.cnf 2. ค้นหาคำว่า bind-address = 127.0.0.1 ….. ในกรณีหาไม่พบให้เข้า Path /etc/mysql แล้วใช้คำสั่ง  #grep -iR “bind-address” ./* ระบบจะแสดง Path  ที่พบคำว่า bind-address แล้วเข้าไปแก้ไขไฟล์นั้น root@freeradius:/etc/mysql# grep -iR “bind-address” ./* ./mysql.conf.d/mysqld.cnf:bind-address = 127.0.0.1 3. ใส่ comment หน้า #bind-address = 127.0.0.1 4. Ctrl+o เซฟ , Ctrl+x ออก 5. สั่ง Restart Service   /etc/init.d/mysqld restart ภักดี โตแดงนักวิชาการคอมพิวเตอร์ งานพัฒนาระบบเครือข่ายเทคโนโลยีดิจิทัล

เพิ่มขนาดไฟล์อัพโหลด

alice@u16:~$ sudo vi /etc/php/7.0/fpm/php.ini ; Maximum size of POST data that PHP will accept. ; Its value may be 0 to disable the limit. It is ignored if POST data reading ; is disabled through enable_post_data_reading. ; http://php.net/post-max-size post_max_size = 128M ; Maximum allowed size for uploaded files. ; http://php.net/upload-max-filesize upload_max_filesize = 128M **************************************************************************** แบบ

Read More