To do this, you need to read the RSS blog, from RSS you need to read the title and description, after reading the entire description and title, you need to trim the description to the desired number of letters. After that, you need to check the weather in the description of the last word that was completed or not, and then you need to delete the last word if it was not completed, and put "...".
First we will make a script to crop the description and put "..." in the last: -
<?php global $text, $maxchar, $end; function substrwords($text, $maxchar, $end='...') { if (strlen($text) > $maxchar || $text == '') { $words = preg_split('/\s/', $text); $output = ''; $i = 0; while (1) { $length = strlen($output)+strlen($words[$i]); if ($length > $maxchar) { break; } else { $output .= " " . $words[$i]; ++$i; } } $output .= $end; } else { $output = $text; } return $output; }
Now we will define the variables in which we store the values: -
$xml=("http://your-blog-path/rss/"); global $item_title, $item_link, $item_description; $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); $x=$xmlDoc->getElementsByTagName('item');
Now we will create an array and store the values โโin it. I accept only 3 because you asked about it. You can change it to anything (the number of messages you want to show, put in a loop)
for ($i=0; $i<3; $i++) { $item_title[$i] = $x->item($i)->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue; $item_link[$i] = $x->item($i)->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue; $item_description[$i] = $x->item($i)->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue; } ?>
Now echo all these values, the link is the value that your user will click on and he will be sent to your blog: -
FIRST LAST MAIL:
<a href="<?php echo $item_link[0]; ?>"><?php echo $item_title[0]; ?></a> <?php echo substrwords($item_description[0],70); ?>
SECOND LAST MAIL:
<a href="<?php echo $item_link[1]; ?>"><?php echo $item_title[1]; ?></a> <?php echo substrwords($item_description[1],70); ?>
THIRD LAST MAIL:
<a href="<?php echo $item_link[2]; ?>"><?php echo $item_title[2]; ?></a> <?php echo substrwords($item_description[2],70); ?>
Hope this helps solve your problem. By the way, a good question.