substr

ဒီနေ့ ရေးလက်စ project တစ်ခုမှာ စာလုံးတွေ ဖြတ်ထုတ်ဖို့ ပါလာတယ်။ id နဲ့ အမျိုးအစားခွဲဖို့လေ။ ဒါနဲ့ ဟိုစမ်းဒီစမ်းနဲ့ ရေးလို့ရသွားတယ်။ ထူးခြားတာက -2 ဆိုတာနဲ့ နောက်က စာလုံး ဖြုတ်ပေးလိုက်တာပဲ။ အဲဒါကို မသိလိုက်တာ။ googling လုပ်လိုက်လို့သိသွားတာ။

$time = "1234_sta";
$length = strlen($time);
$characters = 3;
$start = $length - $characters;
$time1 = substr($time , $start ,$characters);
$time2=substr($time,0,-4);
echo $time1; 
echo "
"; echo $time2;

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.