Jump to content

[SOLVED] using the wordwrap function


dazzclub

Recommended Posts

Hi guys i trying to set a limit to how many characters i want to displayed for my news headline, but i  think im using the wordwrap function wrongly.

 

I'm applying it to the News row

 

Here is my entire code;

function getHeadlines()
{
global $dbc;
$query = "SELECT NewsID, NewsDate, NewsTitle, News FROM news ORDER BY NewsDate";
$result = mysqli_query ($dbc, $query)or die(mysqli_error() . "<p>With query:<br>$query");
while ($row = mysqli_fetch_array($result))
{
//need to format the date on this function
//get NewsID 
echo '<strong class="news_header"><a href="news_article.php?news_article='.$row['NewsID'].' title="erer">'.$row['NewsTitle'].'</a></strong>
	<p class="date">'.$row['NewsDate'].'</p>
	<p class="intro">'.wordwrap($row['News'], '20').'</p>
	';
}
}

 

Any advice would be great :)

Link to comment
https://forums.phpfreaks.com/topic/150983-solved-using-the-wordwrap-function/
Share on other sites

Hi thorpe,

 

The row News, is basicly the whole of the news article, so rather than having the whole article displayed i would like to shorted it to a paragraph. So i though using wordwrap i can reduce the amount of characters being displayed.

 

so in my code above, i was hoping the wordwrap would only display 20 characters (just for testing purposes).

 

The reason i think im using it wrong is when i remove the wordwrap function the amount of characters stays the same..

 

Hope that helps :)

Hi thorpe,

 

Thanks for that! :)

 

here is the finished code if anyone else can find it helpful;

 

function getHeadlines()
{
global $dbc;
$query = "SELECT NewsID, NewsDate, NewsTitle, News FROM news ORDER BY NewsDate";
$result = mysqli_query ($dbc, $query)or die(mysqli_error() . "<p>With query:<br>$query");
while ($row = mysqli_fetch_array($result))
{
//need to format the date on this function
//get NewsID 
echo '<strong class="news_header"><a href="news_article.php?news_article='.$row['NewsID'].' title="erer">'.$row['NewsTitle'].'</a></strong>
	<p class="date">'.$row['NewsDate'].'</p>
	<p class="intro">'.substr($row['News'], '0', '120').'...</p>
	';
}
}

 

Thanks again

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.