Jump to content

Recommended Posts

Hi,

 

I have a newsroom section in one of my projects and

some of the news title are so long.

 

now, my boss wants to limit the number of characters to be displayed

in the lists of news room title to 50 characters only.

 

my problem is, i dont know how to do it.

below is my current code for the listing of news title.

		function getTop3() {
	 	$sql = "SELECT * FROM ilec_news 
		 		WHERE published = 1 
				ORDER BY news_date DESC
				LIMIT 0, 3;";

		$dbConn = new DBConn();
		$con = $dbConn->connect();
		$result = mysql_query($sql);

		$records = array();

		while($row = mysql_fetch_array($result)) {
			$news = new News();

			$news->id = $row['news_id'];
			$news->title = $row['news_title'];
			$news->content = $row['news_content']; 
			$news->pdf_link = $row['news_pdflink'];
			$news->date = $row['news_date'];
			$news->created = $row['news_date_created'];
			$news->published = $row['published'];

			$records[] = $news;
		}

		mysql_close($con);

		return $records;
	}


	echo '<table width="100%">';
	foreach ($records as $row) {
		echo '<tr><td style="padding-left:5px"><span class="text2"><strong>' . date('d F, Y', $row->date) . '</strong><br>' . $row->title . '</span></td></tr><tr><td><hr class="a" align="left" width="130"></td></tr>';
	}
	echo '</table>';
}

 

 

hope you could help me with this.

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/74551-how-to-limit-number-of-characters/
Share on other sites

i got this out of a class you just have to turn it into a function.

<?php
function shortBio($id,$length){
	$query="SELECT bio FROM artist WHERE artist_id='$id'";
	$result=$this->db->query($query);
	$txt = $this->db->fetch_array($result);
	$newtxt =explode(" ",$txt['bio']);

for ($i=0; $i<15; $i++){
   $words .= $newtxt[$i].' ';
}
return stripslashes($words).'...';		
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.