Re: Newbie Question re substr
| From: | Jackson Linux | Date: | Tue, 08 Mar 2005 17:05:51 +0000 |
| Subject: | Re: Newbie Question re substr | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-210236@lists.php.net to get a copy of this message | ||
On 8 Mar 2005, at 11:40, Richard Lynch wrote:
Thanks for taking the time. I had suspected that earlier, but when I put it in all sorts of OTHER stuff happened. Then I saw your post and tried again. I saw that I had made another mistake later on. So you've solved that part - thanks!. Except....Except it doesn't pull the content from the db and substr it to 200 characters. It pulls the id number and the title no problem, and I am sure that $article['content'] points to the right place (or at least it's named right) but it's just not getting the content: if (!empty($where)) { echo " <ul>"; $article = mysql_fetch_assoc($result); } else { while ($article = mysql_fetch_assoc($result)) {In this line, PHP is somehow encountering a T_NUMBER (a number) where it *expects* to see something else. Like a comma. Look between your 0 and 200 very carefully.1. $content = substr($article['content'], 0 200); // get first 200chars is choking, and I've looked in docs and can't understand why. I get Parse error: parse error, unexpected T_LNUMBER in /usr/www/users/domain/dynamic/templates/substr.htm on line 57
// humanize data
$article_id = $article['article_id'];
$title = $article['title'];
$content = substr($article['content'], 0, 400); // get first 200 chars
// print and see if we get, what we expect
// print "id=$article_id<br>title=$title<br>content=$content<p>";
// now make the real stuff
$table_of_contents[] = "<li><a href='{$_SERVER['PHP_SELF']}?a={$article_id}'}&title='{$title}'>{$article['title']}</a><br/$content<br /><a href='{$_SERVER['PHP_SELF']}?a={$article['article_id']}' title='{$article['title']}'> ... [Read article]</a></li></li>";
}
}
echo "
</ul>";
Thanks in advance. . .