Post by Goborijung at 2022-03-14 16:50:15 | ID: 1413
<?php
echo str_replace("world","Peter","Hello world!");
?>Post by Goborijung at 2021-03-08 13:00:56 | ID: 426
>> PHPตัดจากฝั่งซ้าย ตั้งแต่ Index ที่ 4 เป็นต้นไป
<?php echo substr("Hello world",4); // Output : o world ?>ตัดจากฝั่งซ้าย เริ่มจาก Index ที่ 1 เอามา 2 ตัว
echo substr("Hello world",1,2); // Output : elตัดจากฝั่งขวา เอา 5 ตัวสุดท้าย
// Substring Right echo substr("Hello world",-5)."<br>"; //output = worldตัดจากฝั่งขวา เอา 5 ตัวสุดท้าย และเอามา 3 ตัว
echo substr("Hello world",-5,3); //output: wor -- เริ่มจาก index 0 และ ตัดมา 28 ตัว <?php echo mb_substr($rs['QCRemark1'],0,28); ?> >> Javascript <script> var str = "Hello world!"; var res = str.substring(1, 4); </script>
Post by Goborijung at 2022-06-03 14:46:55 | ID: 1583
<?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!";
break;
case "blue":
echo "Your favorite color is blue!";
break;
case "green":
echo "Your favorite color is green!";
break;
default:
echo "Your favorite color is neither red, blue, nor green!";
}
?>
Post by Goborijung at 2021-03-19 11:35:10 | ID: 1054
$thisPage = $_SERVER["PHP_SELF"]; Example : <button class="btn btn-sm btn-danger" type="button" name="reset" onclick="window.location.href='<?=$thisPage?>' "><i class="fa fa-times"></i> Reset</button>
Post by Goborijung at 2021-08-16 08:35:35 | ID: 1316
<?php
function diff2time($time_a,$time_b)
{
$now_time1 = strtotime(date("Y-m-d ".$time_a));
$now_time2 = strtotime(date("Y-m-d ".$time_b));
$time_diff = abs($now_time2-$now_time1);
$time_diff_h = floor($time_diff/3600); // จำนวนชั่วโมงที่ต่างกัน
$time_diff_m = floor(($time_diff%3600)/60); // จำวนวนนาทีที่ต่างกัน
$time_diff_s = ($time_diff%3600)%60; // จำนวนวินาทีที่ต่างกัน
//return $time_diff_h." ชั่วโมง ".$time_diff_m." นาที ".$time_diff_s." วินาที";
return $time_diff_h.".".$time_diff_m.".".$time_diff_s."h";
}
$curTime = substr(date('Y-m-d H:i:s'),11,8);
$cDate = substr($rs['Date'],11,8);
$closeDate = substr($rs['closeDate'],11,8);
$workingTime = $rs['closeDate'] == "" ? diff2time($cDate,$curTime) : diff2time($cDate,$closeDate);
?>Post by Goborijung at 2021-05-19 16:39:33 | ID: 1211
$str = "Hello "; echo trim($str);
Post by Goborijung at 2020-07-10 17:00:09 | ID: 562
PHP User Online Process 1. สร้าง Table สำหรับจัดเก็บ Session User ---------------------------- (1) USE GSSv2_Prod CREATE TABLE WEB_user_online ( session nvarchar(100) NOT NULL, time int(11) DEFAULT '0' NOT NULL, IP nvarchar(20) NOT NULL );
<?php //PHP Code UserOnline ต้องเอาไว้หลัง User-count $session = session_id(); $time = time(); $time_check = $time - (10*60); //กำหนดเวลาในที่นี้ผมกำหนด x นาที $tblname = "user_online"; //กำหนดตารางที่เก็บข้อมูล $session_db = mysqli_query($link,"SELECT COUNT(*) FROM $tblname WHERE session = '$session' "); $session_check = mysqli_fetch_array($session_db); //warning if ($session_check[0] == "0") { mysqli_query($link,"INSERT INTO $tblname VALUES ('$session',$time,'".$_SERVER['REMOTE_ADDR']."')"); } else { mysqli_query($link,"UPDATE $tblname SET time = '$time' WHERE session = '$session' "); } $count_user = mysqli_query($link,"SELECT COUNT(*) FROM $tblname"); $user_onlines = mysqli_fetch_array($count_user); //warning //echo "กำลังใช้งานอยู่ : $user_online คน"; //ทดสอบการแสดงผล ถ้านำไปใช้ให้ปิด หรือลบบรรทัดนี้ออกไป mysqli_query($link,"DELETE FROM $tblname WHERE time < '$time_check' "); mysqli_close($link); ?>
Post by Goborijung at 2018-12-24 17:01:24 | ID: 72
https://www.w3schools.com/php/default.asp
Post by Goborijung at 2020-07-13 09:46:44 | ID: 675
<?php
$car = array(
'Toyota' => array('Vios', 'Yaris', 'Altis', 'Camry'),
'Honda' => array('City', 'Jazz', 'Civic', 'Accord'),
'Nissan' => array('Tiida')
);
echo "<pre>";
print_r($car);
echo "</pre>";
// การเรียกใช้งาน Array 2 มิติ
echo "<br>".$car["Toyota"][0]."<br>";
?>Post by Goborijung at 2022-02-01 11:45:26 | ID: 1365
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]