I think it may be quicker to use a backend application to retreive the messages. Then you need to seperate ech message by either putting it into a database or by dumping it into a file.
If you are using the mysql database use a for loop i.e.
for($i=$startnum,$i<$i+$increment,$i=$i){
$pagecontent .= (grab message $i from mysql);
}
Or if you are using a flat file
$seperator = whatever you want;
$filecontents = file_get_contents("./the messaging file");
$tempdata = explode ($seperator,$filecontents);
for($i=$startnum,$i<$i+$increment,$i=$i){
$pagecontent .= (grab message $i from array);
}
then echo the results or store them. also if you push them into an array you could make the script much more dynamic.
If you need specific mysql help get the mysql query builder through google searching.
Have Fun🙂