limit characters displayed

7 posts by 4 authors in: Forums > CMS Builder
Last Post: March 7, 2011   (RSS)

Re: [s2smedia] limit characters displayed

By Jason - July 26, 2010

Hi,

Take a look at this post:
http://www.interactivetools.com/forum/gforum.cgi?post=77525#77525

Give this a try. If you run into any issues, just let me know.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Jason] limit characters displayed

By sublmnl - February 26, 2011 - edited: February 27, 2011

Little more help guys.
I have talked to Jerry about this too.

I have a limit character-count on field inside a ForEach loop of records. (only one field in the loop needs the limit char)

Weird thing about it is any entry shorter than the number I have chosen in the function gets displayed but anything more than that number, only the first 3 characters of the entry gets displayed with the added ellipses.

Specifically I'm using website addresses in my records and am chopping them down to fit a specific width. (don't worry the link still has the full address [;)] )

I have tested this on the basic pages that the code generator spits out so I know its not any other special code on my page.
I changed the number in the function a few times and counted the resulting 'cutoffs' and came to the above conclusion.
Now maybe I am missing something or is this the desired result???
I thought that the letters would count until the function got its max, take away three letters and then add 3 dots (ellipses) to finish.

If this is not the case - someone wake me up or better yet provide some code that actually does this the right way similar to the max words counter that I'v borrowed from here. Thanks.


Thanks.
[sly]

Re: [sublmnl] limit characters displayed

Here's a little clarity:

Let's say it has a limit of 12. Anything 11 and under displays fully.
Anything 12 and over chars - only displays the first 3 chars plus
ellipses.


Gkornbluth and I have been discussing this and believe the issue is the web url is hacking up the Regex.

So when it finds a "/" or a "." thats what makes it hault and show the first three characters. (duh) because the first three chracters of most URL's are 'www' then the "."

So may I ask for a hand on this one to accomodate URL's in the text limiter function?

Thanks in advance.

[cool]

Re: [sublmnl] limit characters displayed

Here's the code we're having trouble with:
<?PHP function textLimit($string, $length, $replacer = '...')
{
if(strlen($string) > $length)
return (preg_match('/^(.*)\W.*$/', substr($string, 0, $length+1), $matches)
? $matches[1] : substr($string, 0, $length)) . $replacer;

return $string;
}

?>


And
<?PHP echo textLimit($record['web_site_url'], 32) ?>
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] limit characters displayed

By sublmnl - March 6, 2011 - edited: March 6, 2011

Talked to a buddy of mine who is a programmer. Not php but at least he can read the code and validate the Regex is working fine.
He put the same rules in hist regex tester, then put in a web address, with 'www.' and without as well as with the 'http://' - they all passed the test.
So it must be the other half of the function true|false.

I don't know how to write this so I am looking for help to solve this issue.
Anyone have any ideas on why when I put in a web address in the field, that the text limiter cuts it at the dot?

Re: [sublmnl] limit characters displayed

By Jason - March 7, 2011

Hi,

In order to do this, we'll need to create a custom function that will go beyond what we can handle in support. If you'd like us to look into doing this for you, please send and email to consulting@interactivetools.com and we can go over some options with you.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/