ShivaGupta Posted June 21, 2013 Share Posted June 21, 2013 i am using this to get data frm text file...... text file content.345in php $fh=file_get_contents("test.txt"); and it working fine.but here what i want.text file content.345,567,789,in php $fh="345"; $ch="567"; $dh="789"; so plz give me example how to get content.thanx Link to comment https://forums.phpfreaks.com/topic/279421-need-help-file_get_contentstesttxt/ Share on other sites More sharing options...
litebearer Posted June 21, 2013 Share Posted June 21, 2013 hint key word : explode Link to comment https://forums.phpfreaks.com/topic/279421-need-help-file_get_contentstesttxt/#findComment-1437227 Share on other sites More sharing options...
ShivaGupta Posted June 21, 2013 Author Share Posted June 21, 2013 hint key word : explode YA i found this but their is no intrigation into text file. <?php $str = 'one,two,three,four'; // zero limit print_r(explode(',',$str,0)); // positive limit print_r(explode(',',$str,2)); // negative limit print_r(explode(',',$str,-1)); ?> Link to comment https://forums.phpfreaks.com/topic/279421-need-help-file_get_contentstesttxt/#findComment-1437234 Share on other sites More sharing options...
Irate Posted June 21, 2013 Share Posted June 21, 2013 You want to open a file and read its context, then explode on it? Easy. <?php function gc($file) { $stream = fopen($file,"r"); if(!feof($stream)) { $content = file_get_contents($file); $close = fclose($stream); return $content; } else { return false; } } $c = gc("test.txt"); if($c) { $arr = explode(",",$c,2); } print_r($arr); ?>That should work. Edit: And you can easily fetch the content from the array now. <?php $first = $array[0]; // "345" $second = $array[1]; // "567" $third = $array[2]; // "789" ?> Link to comment https://forums.phpfreaks.com/topic/279421-need-help-file_get_contentstesttxt/#findComment-1437237 Share on other sites More sharing options...
AbraCadaver Posted June 21, 2013 Share Posted June 21, 2013 Or just: $fh = explode(',', file_get_contents('test.txt')); Link to comment https://forums.phpfreaks.com/topic/279421-need-help-file_get_contentstesttxt/#findComment-1437268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.