PHP Display

v2^

v2^

Associate
Joined
21 Oct 2002
Posts
1,075
Hello all im after is the function name that i need to use to set how many words i want displayed in a news article.

I have ben looking but my head is not working yet so i was running into walls.

Thanks in advance.
 
I'm guessing this is like a post summary feature you want for the front page, with a ".... read more" style link to the full article?

I don't think there is a particular function to print x number of words, but it would be easy to write one. I'd suggest displaying a certain number of characters rather than words - if someone is using long words you could end up with a much longer post summary than one with small words, for example.
 
Something like this?

Code:
$count = count(explode(" ", $text));
if($count>=50)
	$text .= "... <a href="/article/321/">View full article</a>";
else
	$text .= " <a href="/article/321/">View article</a>";
echo $text;
 
toastyman said:
Something like this?

Code:
$count = count(explode(" ", $text));
if($count>=50)
	$text .= "... <a href="/article/321/">View full article</a>";
else
	$text .= " <a href="/article/321/">View article</a>";
echo $text;


That still prints the entire article though, it doesn't trim it if it's greater than 50...
 
Sorry dont know what I was thinking.

You'd do a loop which runs if the total number of words if greater or equal to 50.
The loop runs for the first 50 words, putting them in a new variable ($text2).
You then do this:
$text2 .= "... <a href="/article/321/">View full article</a>";
Then echo $text2.
 
Just do it in mySQL.

Code:
SELECT
    article_title AS title,
    article_content AS content,
    CONCAT(SUBSTRING_INDEX(article_content, ' ', 50)) AS excerpt
FROM
    articles

That returns the article title, the full content and an excerpt containing the first 50 words of the content.
 
Yeh sorry i meant characters say around the first 200. Im not to fussed about the link appearing if there is more as the link is for people to leave comments, check the blog link in my sig to see what i have. I just need the entries to display 200 chars.
 
Back
Top Bottom