[X] Choose Font Here

Read CSV Data

ကြၽန္ေတာ္ CSV File ကေနျပီး data read လုပ္တာကို ေရးမယ္လို႔ စိတ္ကူးထားပါတယ္။

ဒါက client HTML Form ျဖစ္ပါတယ္။

<form name="search" method="post" action="insert.php" enctype="multipart/form-data">
File to import<br>

<input type="file" name="csvimport" value="" size="40" maxlength="250">
<input type="submit" value="Import">
</form>

insert.php ရဲ႔ code ျဖစ္ပါတယ္။


<?php
$csv = file($_FILES["csvimport"]["tmp_name"]);

PHP ရဲ႔ File Object ကိုသုံးျပီး file ကိုဖတ္တာျဖစ္ပါတယ္။

အဲလို read လိုက္တာနဲ႔ array format ရျပီးသားပါ။ explode ကိုသုံးျပီး array အခန္းထဲက data ကိုျပန္ယူတာပါ။

if(count($csv)>1){


foreach($csv as $val){
$data       = explode(",", $val);
$name     = trim($data[0]);
$address  = trim($data[1]);
$contact  = trim($data[2]);
print_r( "Name: " . $name . "-" ." Address:" . $address ."-". " Contact:" . $contact);
}

}
?>

 

 

Comments (2)
  • myoaung  - CSV ဆိုတာဘ)

    ေခါင္းစဥ္) 29;တိုင္းပါပ) 46; အဲဒါဘာလဲ ဘယ္ေနရာကလဲ ဘယ္လိုအသုံ းခ်လို႕ရတာ လဲရွင္းျပေ ပးပါလို ေတာင္းဆိုပ ါရေစဗ်ာ

  • admin  - Re: myoaung

    ကို myoaung ေရ
    CSV ဆိုတာကေတာ့ File Extension တစ္မ်ိဳးပဲ ျဖစ္ပါတယ္။ ဒီ file format မ်ိဳးကို excel or open office စတာေတြကေန Export လုပ္ယူႏိုင ္ပါတယ္။

Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.

Login Form

Categories Table View

JoomlaWatch Stats 1.2.9 by Matej Koval

Facebook Share

Share on facebook

Accordion FAQ

mod_joomtouch

Version Iphone

Version Iphone by JoomTouch