How to display first X characters?

4 posts by 3 authors in: Forums > CMS Builder
Last Post: August 26, 2008   (RSS)

Re: [samsam92] How to display first X characters?

By samsam92 - August 23, 2008

Found it!

Just add at the top of the page:

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 then where you want to display your content:

<?php echo textLimit($record['content'], 20) ?>

Re: [samsam92] How to display first X characters?

By Jake - August 24, 2008

Hi samsam92,

Thanks for posting this! It could definitely come in handy for some other users. [:)]
-----------------------------------------------------------
Cheers,
Jake Marvin - Product Specialist
support@interactivetools.com

Hire me!
Save time by getting our experts to help with your project. Template changes, advanced features, full integration, whatever you need. Whether you need one hour or fifty, get it done fast with Priority Consulting.

Re: [samsam92] How to display first X characters?

By zip222 - August 26, 2008

Awesome! That is super useful.