This is probably not the best thing to do within your php code. If it's up to me, I'd leave this to the presentation layer and try and handle in the html templates.
Brute force method - breaks a long string into x parts (depending on how many <span id="cols"></span> there are) and inserts them into <td> cells with similar IDs - quick and dirty way - slices words in the middle... warning not tested on anything other than IE6
<html>
<head>
<title>Test</title>
</head>
<body onload="transfertopage('textdata', 'col');">
<script language="javascript">
<!-- //
function transfertopage(strFrom, collectionTo)
{
var objsource = document.getElementById(strFrom);
var iCount = 0;
var arTarget = new Object;
if (objsource && objsource.innerHTML)
{
var strMessage = objsource.innerHTML;
for (element in document.all)
{
if (element == collectionTo)
{
iCount++;
//arTarget[iCount] = arAllElements[element];
arTarget[iCount] = document.all[element];
//alert(element);
}
}
if (iCount > 0)
{
iElementcount = 0;
iStrLength = strMessage.length;
iDivided = strMessage.length / iCount;
lastpoint = 0;
for (element in document.all)
{
if (element == collectionTo)
{
document.all[iElementcount-1].innerHTML = strMessage.substr(lastpoint, lastpoint + iDivided);
lastpoint = lastpoint + iDivided;
//alert(element);
}
iElementcount++;
}
}
else
{
alert('No place to put it');
}
}
}
// -->
</script>
<div id="textdata" style="display:none">
The quick brown fox jumped over the lazy dog...
</div>
</body>
<table width="100%" border="1">
<tr>
<td><span id="col"></span></td>
<td><span id="col"></span></td>
</tr>
</table>
</html>