CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> Archive -> GotoCode Archive

 limiting text

Print topic Send  topic

Author Message
Jerry
Posted: 08/12/2003, 1:27 PM

Has anyone been able to limit the output text?

example:
I have an article that on the main page I only want to show the first 300 characters, then they must click on the article to see the full text. I have tried several ways I have seen on the net, but with no luck yet.

Thanks in advance.
prev
Posted: 08/12/2003, 2:21 PM

from a similar posting and answer from the archive


----

The important thing here is to ensure that you get a snippet not truncated
in the middle of a word. You could use function similar to this one (add it
to your Common.php or wherever you prefer):

// -------------------------------------------------
function smart_truncate($str2cut, $trig_val=30){
$newstr="";

if(strlen($str2cut) <= $trig_val)
return $str2cut;

$newlen=strrpos(substr($str2cut,0,$trig_val)," ");
if($newlen>0)
$newstr=substr($str2cut,0,$newlen);
else
$newstr=substr($str2cut,0,$trig_val);

return $newstr."...";
}

// -------------------------------------------------

Set the $str2cut parameter to the story you want to get a snip from, and
optionally set $trig_val to the maximum length of the resulting string
(defaults to 30 chars.)

To use:

$full_story=CCDLookUp("content_field", "news_table", "id_field=xxx", $db);
$snip_story=smart_truncate($full_story);
-----

hope its some help


feha
Posted: 08/12/2003, 2:57 PM

here we go ...
short... in PHP

if(strlen($text) >=310 ){
$text=substr($text,0,300);
$text="$text ...";
}
$text=str_replace("\n","<br>", $text);
//this above would make nice formating if you show the text in label

echo $text;


regards
feha
(www.vision.to]
Thomas
Posted: 08/12/2003, 10:41 PM

Can you also explain how to do thin in asp?
prev
Posted: 08/13/2003, 8:23 AM

yours works, but you missed the point of what i posted

your system cuts the text at 'exactly' your set number, even if its in the middle of a word

imagine how it lo...

as against

imagine how it looks...

this is why i think the one i posted is more usefull
feha
Posted: 08/13/2003, 4:52 PM

I agree PREV ...

Your code is better ...
(I didn't try your code, but it should work ...)


regards
feha
[www.vision.to]
Jerry
Posted: 08/14/2003, 9:50 AM

I cant get either of these to work... I know I am doing something stupid and little..

With the first example I get the error "Undefined variable: db " I tried several ways to define it, but I must be doing it wrong. What is the correct way?

Thanks in advance.
Jerry
Jerry
Posted: 08/15/2003, 2:24 PM

I got the code in and now have no errors, but it doesnt do anything. It doesnt limit the text. Is there anything I am missing???
glerma
Posted: 08/16/2003, 10:42 AM

Jerry. Are you now assigning the new snipped value to your label control?
This can probably be done in the Before Show Row or Before Show Event of the Form.

You would need to add a third step to the first two:

1. $full_story=CCDLookUp("content_field", "news_table", "id_field=xxx", $db);
2. $snip_story=smart_truncate($full_story);
3. $formname->labelname->SetValue($snip_story);


Make sure this is being done.
glerma
Posted: 08/16/2003, 10:46 AM

Jerry. The reason you were getting the undefined variable error is because you probably did not instantiate your Database Connection Class.

The example showed how to use the CCDLookup function:

CCDLookUp("content_field", "news_table", "id_field=xxx", $db);

$db is the database connection class object that will connect to the database.

In order to do this you must "instatiate" prior to using the function.

Example: $db = new clsDB<ConnectionName>;
(Replace ConnectionName with your own.)

Regards,
george
Jerry
Posted: 08/18/2003, 9:14 AM

Thanks for the help.
I figured out the connection problem. Thats when I got the code in with no errors, but the code didnt do anything to the text.

So I tried to add your 3rd line, but I get parse errors. I think I have the formatting wrong.

You posted it like this:
$formname->labelname->SetValue($snip_story);

I changed it to match my items:
$->info->30($snip_story);

I get:
Parse error: parse error, unexpected T_LNUMBER, expecting T_STRING or T_VARIABLE or '{' or '$' in index2_events.php on line 22

Line 22 is the 3rd line you told me to add. How did I do this wrong.

I really appreciate the help. Sorry if these are dumb questions.
Thanks in advance
Jerry
Posted: 08/18/2003, 9:20 AM

Sorry I put that wrong, the code I added looks like this:
$index_box_1->info->30($snip_story);

Thanks again.
glerma
Posted: 08/18/2003, 12:16 PM

RE:
Sorry I put that wrong, the code I added looks like this:
$index_box_1->info->30($snip_story);
*******************************

What was the outcome of this? Success? Failure?


You should code it like this:
$index_box_1->info->SetValue($snip_story);

Assuming:
$index_box_1 = Your form name.
info = Your label name.
Jerry
Posted: 08/18/2003, 2:42 PM

The outcome was:
Fatal error: Call to a member function on a non-object in index2_events.php on line 22

Line 22 is:
$index_box_1->info->SetValue($snip_story);

index_box_1 is the grid name
info is the label name

Maybe a dumb questions but this is a grid, not a form. Will that make a difference?
DaveRexel
Posted: 08/18/2003, 3:09 PM

Hi Jerry

NADQ (Not A Dumb Question)

>Line 22 is:
>$index_box_1->info->SetValue($snip_story);

Have you got the following line in Event code?

Global $index_box_1;

This allows the event to access your object and its subordinates.

Dave

glerma
Posted: 08/18/2003, 3:47 PM

David. Thanks for the follow-up. I assumed that was in place already.

Jerry
Posted: 08/18/2003, 3:59 PM

No I sure didnt have that. Sorry I am just learning. That fixed it, works perfectly now! You guys have been a great help. I really appreciate it.

Thanks a million,
Jerry
prev
Posted: 08/19/2003, 2:26 AM

you know

a lot of help has gone into helping with this,


and it would 'all' have been so much easier if people would just say when they originally post,

whether they are using CC or CCS
glerma
Posted: 08/19/2003, 6:22 AM

I Agree. I've posted the same pet-peeve myself. I should have asked the question prior to posting my answers.

It definately helps out to know what product.

BUT WOULDN'T IT BE MUCH EASIER IF YES HAD JUST FIXED THEIR DAMN PAGES TO REQUIRE THE PRODUCT ON ALL POSTS!!!!!!!!!

HMM... THAT WOULD BE NICE.
Jerry
Posted: 08/19/2003, 9:52 AM

Sorry about that guys, I didn't know that was an issue or I would have gladly supplied that information. I haven't used CC and assumed this was a CCS support site.

I would agree it would be nice to have a spot on the form where you have to fill in the info of what you are using to go along with your post. That would have saved these comments. Or at least add some type of a recommended way to post or what to include in your post. Hopefully some of the CCS people monitor this and will take it into consideration.

Next time I will know better, but will other new people? Without being told or irritating someone, I'm sure they wont. So please take that into consideration before you snap at someone. I would hate to see someone turned off to ccs because they didn't know any better and one of us got a little upset at them. Hopefully the CCS guys will see that this an issue, no matter how small and possibly trivial, it's still an issue. And we all know issues can lose your customers.

Again, thanks everyone for all the help. And I will remember to next time post all the needed info about what I am using and what language.
Jerry
Posted: 08/19/2003, 10:05 AM

I just read my post and think part of it may have come out wrong. I didn't me for it to sound like I thought you guys snaped at me. No one did. I just know what you mean by it being a pet-peve. And I know how they irritate me and sometimes I snap at people because of it. Sorry, don't take it as saying anything bad about you guys. I didn't mean it to sound that way.
glerma
Posted: 08/19/2003, 2:41 PM

I don't know about the other guy, but I wasn't snapping at you Jerry. I was snapping at Yes Software.

This is a valid issue too, because I have been using codecharge for over two years now. The gotocode site has been a major source of necessary knowledge,ideas and just plain community connection for probably thousands of users now (as Jerry, you can now attest to). It is extremely vital for Yes to recognise this. I have sent several requests pleading for an update to this site. I have no doubt that many others have as well.

This still has not occurred. I don't know what their problem is. It would seem somewhat kind of very ironic if Yes's reason for not updating this site was due to time constraints or other similar reasons. Ironic because they have always touted their applications as RAD platform (Rapid Application Development). It certainly would not do them much harm to at least update this site in the most minor ways (such as sorting the posts by product). This, unfortunately has not been the case. I hope that it will come soon, since this site is a very good way to learn Yes's products.

One can only hope.

-george
Zee
Posted: 10/17/2003, 3:37 PM

Duh! I am still learning. (CCS 2.2, PHP, MySQL)

Example:- Limiting text by Prev
CCDLookUp("content_field", "news_table", "id_field=xxx", $db);


I have everything working, but I get a parse error because I can't figure out how the "id_field=xxx" in the example works (if thats the problem).

The main code is in the 'before show' page event.
The usage code is in the 'before show' of the news content label.

I tried "news_id=news_id".

global $news;
$db = new clsDBleadmill();
$full_story=CCDLookUp("news_content", "news", "news_id= . $news_id" $db);
$snip_story=smart_truncate($full_story);
$news->news_content->SetValue($snip_story);

Could someone show me an example of what I could put to replace the 'xxx'

Thanks alot :)
Cheers ...

   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.