Forum Moderators: coopster
if (strlen($rows['content'])>100)
$rows['content'] = substr($rows['content'],0,100)."...";;
echo $rows['content'] . '<br>'; to restrict the display of more than 100 characters for displaying a short content. The problem I am facing is that sometimes the words are cut in between as shown below
"Redistributions of source code must retain the a..."
I want a... to be a complete and not to break the work in middle
it should be "Redistributions of source code must retain the above..."
How to let the complete word show and then display ...
^ = start of string
. = any character
{1,100} = match as many characters as possible, but at least one and at most 100
(?!....) = negative look ahead read more [webmasterworld.com]
[a-z] = a-z
/i = case insensitive
preg_replace("/^.{1,2}(?![0-9a-zA-Z])/i","...",$rows['content']);
echo $rows['content']; It is not limiting the printed data instead it prints the whole content as
"Redistribution and use in source and binary forms, with or without modification, is permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution."
$snippet = preg_replace(........
print $snippet;
n.b. you don't need a-zA-Z if you use /i as /i makes it case insensitive