homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Restrict returned content

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

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)

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)

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 ;)



Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved