1. จัดการเรื่องเวลาของ Server ที่ต่างกัน
$now = strftime ( "%Y-%m-%d-%H" , strtotime ( "$now -8 hours" )); |
$now บรรทัดแรกคือยังไม่ได้+ค่าความต่างของเวลา
$now ตัวที่สองบวกค่าความต่างของเวลาแล้ว สามารถแก้ไขเวลาได้
2. การต่อ String URL ด้วย "-"
function create_slug( strtolower ( $string )){ |
$slug =preg_replace( '/[^a-z0-9-]+/' , '-' , $string ); |
echo create_slug( 'Create a slug URL from string of text' ); |
จะสะดวกมากสำหรับพวกที่ทำ URL เป็น String ยางๆและมีเว้นวรรค
3. Convert HEX value to RBG
function hextorgb( $hexvalue ){ |
if ( $hexvalue [0] == '#' ) { |
$hexvalue = substr ( $hexvalue , 1); |
if ( strlen ( $hexvalue ) == 6){ |
list( $r , $g , $b ) = array ( $hexvalue [0] . $hexvalue [1], $hexvalue [2] . $hexvalue [3], $hexvalue [4] . $hexvalue [5]); |
} elseif ( strlen ( $hexvalue ) == 3) { |
list( $r , $g , $b ) = array ( $hexvalue [0] . $hexvalue [0], $hexvalue [1] . $hexvalue [1], $hexvalue [2] . $hexvalue [2]); |
return array ( 'R' => $r , 'G' => $g , 'B' => $b ); |
$rgb = hextorgb( '#fff000' ); |
แก้ไขค่าจาก HEX value to RBG ตามนั้นเผื่อใครได้ใช้
4. ดึงภาพจาก gravatar.com
$gravatar = 'http://www.gravatar.com/avatar/' . md5( $email_address ) . '?s=32' ; |
echo '. $gravatar . '" width="32" height="32"/>' ; |
5. Parse JSON in PHP
$json = '{"id":0,"name":"Ashley","surname":"Ford"} ; |
$array =json_decode( $json ); |
No comments:
Post a Comment