Post by Goborijung at 2020-06-23 09:47:24 | ID: 633
>> แปลงด้วย str_split
ตัวอย่างที่ 1.1 ถ้าไม่กำหนดขนาดจะแบ่งเป็น 1 <?php $str = "Hello Share"; $arr1 = str_split($str); print_r($arr1); ?> ตัวอย่างที่ 2.1 แบ่งโดยกำหนดขนาดเป็น 3 <?php $str = "Hello Share"; $arr2 = str_split($str, 3); print_r($arr2); ?> -------------------------------------------------->> แปลงด้วย explode (ถ้าตัด String ด้วยเครื่องหมายกั้น แนะนำอันนี้จะ)
ตัวอย่างที่ 2.1 delimiter เป็น " " <?php $sentence = "share to your friends"; $pieces = explode(" ", $sentence); print_r($pieces); ?> ตัวอย่างที่ 2.2 delimiter เป็น ',' <?php $input = "share,olanlab"; print_r(explode(',' , $input)); ?> ตัวอย่างที่ 2.3 delimiter เป็น '|' และ limit เป็น 2, -1 <?php $str = 'one|two|three|four'; // positive limit print_r(explode('|', $str, 2)); // negative limit (since PHP 5.1) print_r(explode('|', $str, -1)); ?>
Post by Goborijung at 2021-04-21 12:49:09 | ID: 1136
<?php function calInstallment($carPrice,$percenMoneyDown,$percenInterest,$installment) { // Input $carPrice = $carPrice; $percenMoneyDown = $percenMoneyDown; // % เงินดาวนน์ $percenInterest = $percenInterest; // อัตราดอกเบี้ย % ต่อปี $installment = $installment; // จำนวนงวด // Process $moneyDown = $carPrice*($percenMoneyDown/100); //เงินดาวน์ $moneyTotal = ($carPrice - $moneyDown); //ยอดคงเหลือ(ไม่รวมดอกเบี้ย) $InterestPerYear = $moneyTotal*($percenInterest/100); //ดอกเบี่ยต่อปี $convInstallmentToYear = $installment/12; //คิดค่างวดเป็นปี $InterestTotal = $InterestPerYear*$convInstallmentToYear; //ดอกเบี้ยรวม $moneyWithInterest = $moneyTotal+$InterestTotal; //ยอดท้้งหมดรวมดอกเบี่้ย $payperinstallment = $moneyWithInterest/$installment; //ยอดชำระในแต่ละงวด(เดือน) $moneyTotalPay = $carPrice+$InterestTotal; // ยอดชำระทั้งสิ้น $moneyDiff = $moneyTotalPay-$carPrice; // ส่วนต่าง // Output echo 'ราคารถ : '.number_format($carPrice).'<br>'; echo 'เงินดาวน์(%) : '.$percenMoneyDown.'%<br>'; echo 'อัตราดอกเบี้ย(ต่อปี) : '.$percenInterest.'% <br>'; echo 'จำนวนงวด : '.$installment.' ('.$convInstallmentToYear.'ปี)<br>'; echo '<hr>'; echo 'คิดเป็นเงินดาวน์(บาท) : '.number_format($moneyDown).'<br>'; echo 'ยอดคงเหลือทั้งหมด(ไม่รวมดอกเบี้ย) : '.number_format($moneyTotal).'<br>'; echo 'ดอกเบี้ย('.$percenInterest.'%) ต่อปี : '.number_format($InterestPerYear).'<br>'; echo 'ดอกเบี้ย('.$percenInterest.'%) ต่อเดือน : '.number_format($InterestPerYear/12).'<br>'; echo 'ดอกเบี้ยรวม('.$convInstallmentToYear.'ปี) : '.number_format($InterestTotal).'<br>'; echo 'ยอดชำระทั้งสิ้น(รวมดอกเบี้ย) : '.number_format($moneyWithInterest).'<br>'; echo 'ยอดชำระต่องวด(เดือน) : '.number_format($payperinstallment).'<br>'; echo 'ยอดชำระต่อวัน : '.number_format($payperinstallment/30).'<br>'; echo 'ยอดชำระทั้งสิ้น : '.number_format($moneyTotalPay).'<br>'; echo 'ส่วนต่าง : '.number_format($moneyDiff); } //calInstallment(ราคารถ,เงินดาวน์(ex 30%),ดอกเบี้ยต่อปี(ex 5%),จำนวนงวด); calInstallment(539000,5,4.59,84); ?>
Post by Goborijung at 2020-02-27 14:44:05 | ID: 409
<?php function br(){echo '<br>';} // หาวันสุดท้ายของเดือนปัจจุบัน echo date('Y-m-t',strtotime('today')); br(); // หาวันสุดท้ายของเดือนต่อไป echo date('Y-m-t',strtotime('next month')); br(); // หาวันสุดท้ายของเดือนอื่นๆที่กำนหด echo date('Y-m-t',strtotime('2014-02-21')); br();
Post by Goborijung at 2020-02-24 02:57:42 | ID: 408
<?php //array_push($assocCar, $assocCar["make"] = 'BMW'); $newArray = array(); array_push ($newArray,$newArray['key']='val' ); array_push ($newArray,$newArray['This']='is' ); print_r($newArray); echo '<hr>'; foreach($newArray as $key => $val) { echo $key.'::'.$val.'<br>'; } echo $newArray['key'];
Post by Goborijung at 2020-01-13 16:46:12 | ID: 365
<?php //input $page = 10; $perpage = 1000; $arrow = 4; //Something is wrong prev-next page //process $start = ($page - 1) * $perpage; $sql = "SELECT * FROM Products OFFSET {$start} ROWS FETCH NEXT {$perpage} ROWS ONLY"; //Output echo 'StartRow: '.$start; echo "<br>".$sql; /* --------------------------------------- */ $totalReccord = 1000000; $totalPage = $totalReccord/$perpage; echo '<br>Total Page: '.$totalPage.'<br><br>'; echo "<< "; //prev if(($page-$arrow) < 1){$firstPage = 1; }else{$firstPage = $page-$arrow;} if(($page+$arrow) > $totalPage){$endPage = $totalPage; }else{$endPage = $page+$arrow;} for($i=$firstPage; $i<=$endPage;$i++) { if($i==$page) { echo "<b style='color:red'>".$i."</b> "; } else { echo $i.' '; } } echo " >>"; //next
Post by Goborijung at 2020-02-07 09:17:58 | ID: 399
// Convert String strval(var) // Convert Int intval(var) // Convert Double doubleval(var)
Post by Goborijung at 2020-02-03 11:10:05 | ID: 393
<?php include 'config.php'; $file = "test.xlsx"; header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment; filename='.$file); $sql = "SELECT * FROM Branch WHERE GCRecord IS NULL"; $qry = sqlsrv_query($conn,$sql); $content = ''; if($qry) { $content .= "OID,Name "; while($rs = sqlsrv_fetch_array($qry)) { $content .= $rs['OID'].",".$rs['Name']." "; } } echo $content; ?>
Post by Goborijung at 2020-01-16 08:34:03 | ID: 367
<?php $filename = "ItemOnHand.xls"; header("Content-Type: application/xls"); header("Content-Disposition: attachment; filename=$filename"); header("Pragma: no-cache"); header("Expires: 0"); ?>
Post by Goborijung at 2021-02-09 11:54:45 | ID: 400
// GET Type Variable gettype(var) // gettype of list object : date double : 10.01 integet : 10 string : '10'
Post by Goborijung at 2019-12-23 22:36:32 | ID: 353
-- Download PHP https://www.php.net/downloads.php