Well, if you were posting it to a database, all you'd do is put it into a variable, rather than echoing. See below 🙂
<?php
$sentence = "Only one word is too long: Pneumonoultramicroscopicsilicovolcanoconiosis";
// Split up $sentence, so you can test each word
$words = explode(" ", $sentence);
// Loop through the array created by explode
foreach($words as $longword) {
// Check the length of the word
if(strlen($longword) > 25) {
// If this ISN'T the first word put in a newline before the long word
if(!empty($InsString)) {
$InsString .= "\n";
}
// Loop through the word itself, splitting it up using substr
for($i=0; ($i*25) < strlen($longword); $i++) {
// the offset is needed to get the right part of the word
$offset = $i*25;
$InsString .= substr($longword, $offset, ($offset+25)).'\n';
}
// Else, just display the word with a space before hand (explode will strip the spaces)
} else {
$InsString .= " ".$longword;
}
}
// Put your code to insert $InsString into the database here
$db = mysql_connect("localhost","user","pass") or die("Could not connect to database server");
mysql_select_db("dbname", $db) or die("Could not select database");
$sql = "INSERT INTO tablename (fieldname) VALUE ($InsString)";
mysql_query($sql, $db) or die(mysql_error());
?>