File splitter





8
Date Submitted Tue. Nov. 14th, 2006 1:24 PM
Revision 1 of 1
Scripter shachi
Tags File | PHP | splitter
Comments 0 comments
This function simply splits a file based on the splitter supplied and returns an array with the values. It's pretty much like the file() function. This script could be helpful in section editings.


<?php
function filesplit($file, $splitter){
$cont = file_get_contents($file);
$cont = explode($splitter, $cont);
return $cont;
}

$fspl = filesplit("filesplit.txt", "----------END----------");
?>


 


bla bla bla bla bla bla                                  

----------END----------

sdfljkdjkslfkjdfsjkfdskjlsdf
sdflfdlsjkjldfsjlkdfs
dsffdsjlkdfsjlkfdsjklfsdljkdjlkfs
dfslkdljkfsjsjdflkjlkdfsjlk

----------END----------

dfsjkldskfljkfdsjlkfdslkjfdsjklfds
fdslkjkjfdskjldfskjkjfd
fdslksfdjfdsljkdfsjkldfjksjkfdl


 


<?php
include('filesplit.php');
$sects = filesplit("filesplit.txt", "----------END----------");
for($i=0;$i<count($sects);$i++){
?>
<span id="someid">
<?php
echo $sects[$i];
?>
</span>
<?php
}
?>

 

Shachi Bista

Comments

There are currently no comments for this snippet.

Voting