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);
?>