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++; } ?> Link to comment https://forums.phpfreaks.com/topic/193173-substr-help/ 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. Link to comment https://forums.phpfreaks.com/topic/193173-substr-help/#findComment-1017239 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.