close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

limiting output

Thread began 6/05/2010 6:33 am by web364946 | Last modified 8/24/2010 9:11 am by Jason Byrnes | 4571 views | 23 replies |

web364946

limiting output

Hi,
I am trying to create a page, which the used will be able to update herself using Power CMS.
On the index page, I only want to display part of the content, let´s say the first 200 characters, and then to read the remaining content, the user will have to click on "more".
I found a previous entry in this forum, concerning the same issue - your suggestion was to use the following entry:

<?php echo substr(WA_getCMSContent($database_localhost, $localhost,"Home Page", "Welcome"), 0, 150)."..."; ?>

Using my own settings, this should correspond to:
<?php include('cms102/WA_CMS/addtosite.php'); echo substr(WA_getCMSContent($database_localhost, $localhost, 'index.php' , 'content') "), 0, 150)."...";?>

However, when using this, I only get either a blank page, i.e. no content showing at all (not even background color or any design details) or error 500.
What am I doing wrong and how can I get the page to work?

Sign in to reply to this post

anonymous

I would actually do it like this:

First add this function at the top of your page:

php:
<?php

// CUTTEXT

function cutText($string$length) {

if(
$length<strlen($string)){

while (
$string{$length} != " ") {

$length--;
}

return 
substr($string0$length);

}else return 
$string;


?>



Then, where your content is:

php:
<?php 

include('cms102/WA_CMS/addtosite.php'); 

$content = (WA_getCMSContent($database_localhost$localhost'index.php' ,  'content');   

$content strip_tags($content'<p><a>');

$content cutText($content150);
    
echo 
$content;

?>



Now, I know this looks like a bit more code, but it will be better in the end because you will use the Strip Tags function to strip out any html tags - such as image tags or other tags that will actually eat up character length. The other problem if you don't strip tags is what happens when your substring ends in the middle of an open html tag such as an image.

In the example I provided, you'll notice after the strip tags command in the parenthesis, I have "<p><a>" as the second attribute. This means that all html tags EXCEPT the p and a tags will get stripped. I usually do this to leave the paragraphs and links in tact while getting rid of images and all other stuff for preview purposes.

After I strip the tags, I then call the custom Cut Text function to trim it down to what I want.

Regards,

Brian

Sign in to reply to this post

web364946

Thanks for your reply! I have tried to do as suggested, but keep getting either a blank page or error 500. What am I doing wrong? I have literally copied the code you sent and pasted it in at the correct (I hope) place - still not working!
I'll be happy to send you the ftp/login details if you want to take a look.
Thanks again.

Sign in to reply to this post

web364946

I am still having problems with this- any suggestions?

Sign in to reply to this post

Jason ByrnesWebAssist

add the following to line 1 to turn error reporting on:

php:
<?php

error_reporting
(E_ALL);
ini_set('display_errors','on');
?>




we will need to know the error that is occurring to have an idea about the cause.

Sign in to reply to this post

web364946

I have added the code as you suggested.

The page in question can be found on the following address (or should be found at least; at the moment I am just getting error 500)

index3.php

Sign in to reply to this post

web364946

Any news on this?

Sign in to reply to this post

Jason ByrnesWebAssist

It's impossible to tell what may be wrong without knowing the error message.


Perhaps if you could send a copy of the index3.php page, i could spot something, other than that, you should check with the host to see if they can look into the server error logs to find the error message.

Sign in to reply to this post

web364946

Here is the code:

==========================

<?php
error_reporting(E_ALL);
ini_set('display_errors','on');
?>
<?php

// CUTTEXT

function cutText($string, $length) {

if($length<strlen($string)){

while ($string{$length} != " ") {

$length--;
}

return substr($string, 0, $length);

}else return $string;
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/forlag404_3.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Förlag 404</title>
<!-- InstanceEndEditable -->
<link href="css/css.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body bgcolor="#000000">
<p>&nbsp;</p>
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<th width="36" rowspan="11" scope="col">&nbsp;</th>
<th width="160" height="20" scope="col">&nbsp;</th>
<th width="20" height="20" scope="col">&nbsp;</th>
<th width="700" height="20" scope="col">&nbsp;</th>
<th width="20" height="20" scope="col">&nbsp;</th>
</tr>
<tr>
<td colspan="3"><img src="images/banner.jpg" alt="" width="860" height="100"></td>
<td width="20">&nbsp;</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3"><table width="850" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="1" bgcolor="#D31424" scope="col"></td>
</tr>
</table></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3">&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="160" height="50">&nbsp;</td>
<td width="20">&nbsp;</td>
<td width="700">&nbsp;</td>
<td width="20">&nbsp;</td>
</tr>
<tr>
<td width="160" valign="top"><!-- #BeginLibraryItem "/Library/nav.lbi" --><table width="160" border="0" cellpadding="0" cellspacing="0" id="nav">
<tr>
<th scope="col"><img src="images/lankar.jpg" alt="" width="157" height="300" border="0" usemap="#Map">
<map name="Map">
<area shape="rect" coords="6,5,152,37" href="index.php" target="_parent" alt="Startsidan">
<area shape="rect" coords="6,40,153,70" href="pages/bocker.php" target="_parent" alt="Böcker"><area shape="rect" coords="3,144,148,182" href="pages/kompisar.php" target="_parent" alt="Våra kompisar">
<area shape="rect" coords="3,73,153,104" href="pages/om_forlag404.php" target="_parent" alt="Om Förlag404">
<area shape="rect" coords="3,107,152,140" href="pages/kontakt.php" target="_parent" alt="Kontakta Förlag 404">
<area shape="rect" coords="3,185,146,213" href="pages/bestall.php" target="_parent" alt="Beställa böcker">
<area shape="rect" coords="6,258,108,304" href="http://www.facebook.com/pages/Offerdal-Sweden/Forlag-404/123065114393977?ref=ts&__a=7&v=wall" target="_blank">
</map></th>
</tr>
</table><!-- #EndLibraryItem --></td>
<td width="20">&nbsp;</td>
<td width="700" valign="top"><table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="480" valign="top" scope="col"><div align="left"><!-- InstanceBeginEditable name="content" -->
<table width="480" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="30" scope="col"><div align="left"><img src="images/redaktoren.gif" width="163" height="30" border="0"></div></th>
</tr>
<tr>
<td height="30"><div align="left"></div></td>
</tr>
<tr>
<td><div align="left"><?php

include('cms102/WA_CMS/addtosite.php');

$content = (WA_getCMSContent($database_localhost, $localhost, 'index3.php' , 'content');

$content = strip_tags($content, '<p><a>');

$content = cutText($content, 150);

echo $content;

?> </div></td>
</tr>
</table>
<!-- InstanceEndEditable --></div></td>
<th width="20" scope="col"><div align="left"></div></th>

<td width="200" valign="top" scope="col"><table width="200" border="0" cellpadding="0" cellspacing="0" id="column">
<tr>
<td valign="top" scope="col"><div align="left"><!-- InstanceBeginEditable name="column" -->
<table width="200" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="30" scope="col"><div align="left"><img src="images/aktuellt.jpg" alt="Aktuellt" width="160" height="30" border="0"></div></td>
</tr>
<tr>
<td height="30"><div align="left"></div></td>
</tr>
<tr>
<td><div align="left">
<table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td scope="col"><div style="height: 300px; width: 200px; overflow: auto;"><table border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="#ffffff" id="updates" >

<tr>
<td height="30" valign="top" scope="col"><div align="left"></div> <p>&nbsp;</p>
<div align="right"></div></td>
</tr>
</table>
</div></td>
</tr>
</table>
</div></td>
</tr>
</table>
<!-- InstanceEndEditable --></div></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="20">&nbsp;</td>
</tr>
<tr>
<td width="160">&nbsp;</td>
<td width="20">&nbsp;</td>
<td width="700">&nbsp;</td>
<td width="20">&nbsp;</td>
</tr>
<tr>
<td width="160">&nbsp;</td>
<td width="20">&nbsp;</td>
<td width="700">&nbsp;</td>
<td width="20">&nbsp;</td>
</tr>
<tr>
<td colspan="4"><table width="850" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#c01921">
<tr>
<th height="1" scope="col"></th>
</tr>
</table></td>
</tr>
<tr>
<td colspan="4"><table width="900" border="0" align="right" cellpadding="0" cellspacing="0">
<tr valign="bottom">
<td width="100" scope="col">&nbsp;</td>
<td scope="col"><div align="center"><a href="http://www.getawebsite.se" target="_blank" class="owd">©Design: Offerdals Web & Development</a></div></td>
<td width="100" height="71" background="images/corner.jpg" scope="col">&nbsp;</td>
</tr>
</table></td>
</tr>
</table>
<p>&nbsp;</p>

</body>
<!-- InstanceEnd --></html>

Sign in to reply to this post

Jason ByrnesWebAssist

Please dont paste the code into the message, instead compress the original php file into a zip archive and attach the zip archive to you reply.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...