uswege Posted February 24, 2010 Share Posted February 24, 2010 I have a code that pulls data from mysql. The codes pulls the first 321 characters. (including spaces). It however cuts words, can any one help me to tune it in way that it will not cut words and will eliminated white spaces. Below is the code, your help will highly be appreciated! <?php include 'connect.php'; $query="SELECT * FROM main WHERE main.category='1' ORDER BY id DESC LIMIT 1"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $content=mysql_result($result,$i,"content"); echo substr($content, 0, 321); $i++; } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted February 24, 2010 Share Posted February 24, 2010 Take a look at some of the example functions on the substr man page. These are always a good resource. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.