Hi,

I am using substr to bring back only the first few lines of text from a database field -

For example:
$message_contents = substr($message_contents, 0, 43);

How can I protect against the substr to deliver the next full word ?

so, if my 44th,45th,46th charachters were (com)
currently the substr will just deliver daniweb. ?? but I would like to display all of the last word

any pointers as always will be very much appreciated -

From http://php.net/manual/en/function.substr.php

echo substr('abcdef', 1); // bcdef
echo substr('abcdef', 1, 3); // bcd
echo substr('abcdef', 0, 4); // abcd
echo substr('abcdef', 0, 8); // abcdef
echo substr('abcdef', -1, 1); // f
echo substr('abcdef', 2, -1); // cde

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.