Jump to content

Readmore


unidox

Recommended Posts

I'd probably just show the first few words of a given article, which could be achieved by exploding by a space, and echoing the first few words. For example:

<?php
$str = 'Here is my news arcticle that i only want to show the first few words of';
$num_words = 3;
$words = explode(' ',$str);
$i = 0;
$teaser = '';
while($i<$num_words){
$teaser .=' '.$words[$i];
$i++;
}
echo $teaser;
?>

 

You'd then include a link after that to read the whole article.

Link to comment
Share on other sites

that is a nasty idea to explode that big string, instead way better idea is find the first  punctuation mark that falls greater than X characters in (like 10ish).  Then just echo out a cut string from 0-that mark, unless that mark is greater than Y characters (say y is 25ish) then it just shows the first Y characters. By exploding you going to make a lot of useless data.  Exploding this post alone is like a 50 item array, vs a test for that comma, and then simply displaying that portion up to it.

Link to comment
Share on other sites

Um, darkfreaks $str would have to be an integer for that to be true.

 

strlen() would do what darkfreaks is showing.

 

<?php
$string = "i like to spam chats and have fun while randomly typing sentences using only my pointer fingers can this sentence have any more run ons?";

if(strlen($string) > 100){
$dot = " ...";
}else {
$dot = "";
}

echo substr($string,0,100) . $dot;
?>

 

Will show:

 

i like to spam chats and have fun while randomly typing sentences using only my pointer fingers can ...

Link to comment
Share on other sites

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.