Not sure what your delimiters are, but you could something like the following (kinda ugly, but it gets the job done):
$namesAndContent = explode("\r\n\r\n", $theString);
$nameRows = explode("\r\n", $namesAndContent[0]);
$names = array();
foreach ($nameRows as $row) {
$items = preg_split('/\s{2,}/', $row);
foreach ($items as $index => $namePart) {
if (!array_key_exists($index, $names)) {
$names[$index] = array();
}
$names[$index][] = $namePart;
}
}
foreach ($names as $name) {
echo implode(' ', $name) . "\r\n";
}
echo "\r\n";
echo $namesAndContent[1];
Demo: http://codepad.viper-7.com/Nr1Q4t
The above would format the data (when the delimiters are correct), but I am wondering where the data is coming from (originaly and not the pdf), because I suspect there is a better way to solve your problem. Perhaps there is some API you can directly utilize