Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Restrict returned content



11:58 am on Dec 10, 2002 (gmt 0)

10+ Year Member

Hi all,

I have just completed a CMS in PHP/MySQL and the final task I'm struggling with is controlling the amount of content returned.

In my 'Articles' section I call:

eval ( StripSlashes( $thisDoc["xml_content"] ) );

Which is the actual document content itself (which may or may not contain more PHP). My problem is how to control the amount of content returned. Some articles should be spread over 3 or 4 pages, not just 1.

Is there a way I can:
a) Restrict the content returned without having to count the first 2000 characters or something similar?
b) Return content without splitting in the middle of a potential PHP tag?




12:31 am on Dec 11, 2002 (gmt 0)

10+ Year Member

Hey aspr1n,
a) I haven't used other than this:
$content = substr($xml_content,0,2000);

However, you can make it a bit more complex by finding the previous period to the 2,000 chars. and chop it there. It will look better.

Another idea would be to place some kind of "special separators" that you can use to identify blocks of content and display as needed.

b) is not so easy.
You have to find out where the PHP and check if it is withing the first X characters you want from the content and cut it there.
Maybe something like:

$where_php = strpos($xml_content,"<?");
if ($where_php!==false) {
// not found, there is no PHP in this one
$content = substr($xml_content,0,2000);
} else {
// there is PHP, where is it?
if ($where_php>2000) {
$content = substr($xml_content,0,$where_php);
} else {
$content = substr($xml_content,0,2000);

Don't know if it will work, I didn't test it, just typed it as it came to my mind.
Good luck! :)


1:48 am on Dec 11, 2002 (gmt 0)

10+ Year Member

Thanks very much transistor, you have of course kindly reminded me to RTFM on substr at the PHP manual where there are more such solutions such as word splitters etc ;)




Featured Threads

Hot Threads This Week

Hot Threads This Month