Reputation: 13
In my text file I have sentences like this:
word word word word word. twoword word word word word. threeword word word word word. fourword word word word word. fiveword word word word word.
I want to split the text file by full stop and have each sentence in a new text file . I know I have to use file_put_content and foreach statement but I am struggling with getting my head around it. Any help please!
Upvotes: 0
Views: 1300
Reputation: 11943
$text = "word word word word word. twoword word word word word. threeword word word word word. fourword word word word word. fiveword word word word word.";
$splitted_text = explode(".", $text);
for($i = 0; $i < count($splitted_text); $i++){
file_put_contents("file_$i", $splitted_text[$i].'.');
//to display a file just use echo file_get_contents($file_name) as such :
echo "file $i :<br/>";
echo file_get_contents("file_$i"); //note that you could echo $splitted_text[$i]
echo "<hr/>";
}
Upvotes: 0