Select only the frist 255 characters. (PHP MySQL and RSS)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Steve Smith
Forum Newbie
Posts: 4
Joined: Sat Apr 05, 2003 4:36 pm
Location: Michigan State University

Select only the frist 255 characters. (PHP MySQL and RSS)

Post by Steve Smith »

I have searched this forum, and the PHP Manual with no results. So I must post a noob question here. Forgive me.

I am hand building a simple CMS for my persona website. I using PHP and MySQL.

The problem I am having is in the PHP code I am using to serve up an RSS feed. I have everything working in it with the exception of the description.

All I am looking to do is display the first 255 characters. So I need a way to clip off the rest of the string. Either in PHP or the MySQL querey.

I am sure there is simply a built in function of this, however I can not find it.

The RSS PHP code if you are interested.

Code: Select all

<?php
header('Content-type: text/xml', true);
print '<?xml version="1.0" encoding="UTF-8"?>';

require('cms/connect.php'); 

$sql1 = "select * from blog order by dateposted desc limit 10;";
$result1 = @mysql_query($sql1) or die("could not complete your query");
?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Shift-8</title>
    <link>http://shift-8.com/</link>
    <description>Shift-8.com is the personal website of Steven Smith.</description>
    <language>en-us</language>
<?php

while($row1 = mysql_fetch_array($result1)){

$permalink = $row1["dateposted"];
$mtndate = $row1["dateposted"];
$title = $row1["title"];
$post = $row1["post"];

$post = strip_tags($post);

$localdate = $mtndate + 7200;

$readdate = date("Y-m-d", $localdate);

print"\t<item>\n";
print"\t\t<title>$title</title>\n";
print"\t\t<link>http://shift-8.com/?view=archives&post=$permalink</link>\n";
print"\t\t<description>$post</description>\n";
print"\t</item>\n";
}
?>
  </channel>
</rss>
<?php mysql_close($connect);
?>
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$post = substr(strip_tags($post), 0, 255);

Presuming it's post you want the first 255 chars of.
Steve Smith
Forum Newbie
Posts: 4
Joined: Sat Apr 05, 2003 4:36 pm
Location: Michigan State University

Post by Steve Smith »

Thank you very much. That is exactly what I was looking for.
Post Reply