Divide String into Parts
Posted: Wed Nov 22, 2006 7:12 am
I have a text file with this in it:
I've got this far:
But nothing is happening all I get is an array[0] not anyother parts....
I want to make PHP divide the text into an array where everything before:# RUle 1
# Rule 2
# ---
# Start Codes
# ---
# ---
# End Codes
# ---
goes into $part[0]# ---
# Start Codes
# ---
goes into $part[1]; the stuff between the# ---
# Start Codes
# ---
goes to $part[2]; and the# ---
# Start Codes
# ---
and
# ---
# End Codes
# ---
goes to $part[3]; and anything after the# ---
# End Codes
# ---
Goes to $part[4].# ---
# End Codes
# ---
I've got this far:
Code: Select all
<?php
$myFile = "thefile.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
$start = split("# --- /n
# Start Codes/n
# ---", $theData, 1);
$part = split("# ---
# End Codes
# ---", $start);
?>