Jump to content

substr() help


uswege

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.